forked from vdesabou/kafka-docker-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-service-bus.sh
executable file
·93 lines (79 loc) · 4.1 KB
/
azure-service-bus.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
source ${DIR}/../../scripts/utils.sh
# https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-cli#send-and-receive-messages
if [ ! -f ${DIR}/QueuesGettingStarted/target/queuesgettingstarted-1.0.0-jar-with-dependencies.jar ]
then
log "Building jar queuesgettingstarted-1.0.0-jar-with-dependencies.jar"
docker run -it --rm -e KAFKA_CLIENT_TAG=$KAFKA_CLIENT_TAG -v "${DIR}/QueuesGettingStarted":/usr/src/mymaven -v "$HOME/.m2":/root/.m2 -v "${DIR}/QueuesGettingStarted/target:/usr/src/mymaven/target" -w /usr/src/mymaven maven:3.6.1-jdk-11 mvn package
fi
if [ ! -z "$AZ_USER" ] && [ ! -z "$AZ_PASS" ]
then
log "Logging to Azure using environment variables AZ_USER and AZ_PASS"
set +e
az logout
set -e
az login -u "$AZ_USER" -p "$AZ_PASS"
else
log "Logging to Azure using browser"
az login
fi
AZURE_NAME=playground$USER$TRAVIS_JOB_NUMBER
AZURE_NAME=${AZURE_NAME//[-._]/}
AZURE_RESOURCE_GROUP=$AZURE_NAME
AZURE_SERVICE_BUS_NAMESPACE=$AZURE_NAME
AZURE_SERVICE_BUS_QUEUE_NAME=$AZURE_NAME
AZURE_REGION=westeurope
set +e
az group delete --name $AZURE_RESOURCE_GROUP --yes
set -e
log "Creating Azure Resource Group $AZURE_RESOURCE_GROUP"
az group create \
--name $AZURE_RESOURCE_GROUP \
--location $AZURE_REGION
log "Creating Azure Service Bus namespace"
az servicebus namespace create \
--name $AZURE_SERVICE_BUS_NAMESPACE \
--resource-group $AZURE_RESOURCE_GROUP \
--location $AZURE_REGION
log "Creating Azure Service Bus Queue"
az servicebus queue create \
--name $AZURE_SERVICE_BUS_QUEUE_NAME \
--resource-group $AZURE_RESOURCE_GROUP \
--namespace-name $AZURE_SERVICE_BUS_NAMESPACE
log "Get SAS key for RootManageSharedAccessKey"
AZURE_SAS_KEY=$(az servicebus namespace authorization-rule keys list \
--resource-group $AZURE_RESOURCE_GROUP \
--namespace-name $AZURE_SERVICE_BUS_NAMESPACE \
--name "RootManageSharedAccessKey" | jq -r '.primaryKey')
${DIR}/../../environment/plaintext/start.sh "${PWD}/docker-compose.plaintext.yml"
log "Creating Azure Service Bus Source connector"
docker exec -e AZURE_SERVICE_BUS_QUEUE_NAME="$AZURE_SERVICE_BUS_QUEUE_NAME" -e AZURE_SERVICE_BUS_NAMESPACE="$AZURE_SERVICE_BUS_NAMESPACE" -e AZURE_SAS_KEY="$AZURE_SAS_KEY" connect \
curl -X PUT \
-H "Content-Type: application/json" \
--data '{
"connector.class": "io.confluent.connect.azure.servicebus.ServiceBusSourceConnector",
"kafka.topic": "servicebus-topic",
"tasks.max": "1",
"azure.servicebus.sas.keyname": "RootManageSharedAccessKey",
"azure.servicebus.sas.key": "'"$AZURE_SAS_KEY"'",
"azure.servicebus.namespace": "'"$AZURE_SERVICE_BUS_NAMESPACE"'",
"azure.servicebus.entity.name": "'"$AZURE_SERVICE_BUS_QUEUE_NAME"'",
"azure.servicebus.subscription" : "",
"azure.servicebus.max.message.count" : "10",
"azure.servicebus.max.waiting.time.seconds" : "30",
"confluent.license": "",
"confluent.topic.bootstrap.servers": "broker:9092",
"confluent.topic.replication.factor": "1"
}' \
http://localhost:8083/connectors/azure-service-bus-source/config | jq .
sleep 5
log "Inject data in Service Bus, using QueuesGettingStarted java program"
SB_SAMPLES_CONNECTIONSTRING="Endpoint=sb://$AZURE_SERVICE_BUS_NAMESPACE.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=$AZURE_SAS_KEY"
docker exec -e SB_SAMPLES_CONNECTIONSTRING="$SB_SAMPLES_CONNECTIONSTRING" -e AZURE_SERVICE_BUS_QUEUE_NAME="$AZURE_SERVICE_BUS_QUEUE_NAME" simple-send bash -c "java -jar queuesgettingstarted-1.0.0-jar-with-dependencies.jar"
sleep 5
log "Verifying topic servicebus-topic"
timeout 60 docker exec connect kafka-avro-console-consumer -bootstrap-server broker:9092 --property schema.registry.url=http://schema-registry:8081 --topic servicebus-topic --from-beginning --max-messages 10
log "Deleting resource group"
az group delete --name $AZURE_RESOURCE_GROUP --yes