This repository has been archived by the owner on Nov 18, 2021. It is now read-only.
forked from vdesabou/kafka-docker-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
salesforce-platform-events-source.sh
executable file
·82 lines (66 loc) · 3.13 KB
/
salesforce-platform-events-source.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
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
source ${DIR}/../../scripts/utils.sh
SALESFORCE_USERNAME=${SALESFORCE_USERNAME:-$1}
SALESFORCE_PASSWORD=${SALESFORCE_PASSWORD:-$2}
CONSUMER_KEY=${CONSUMER_KEY:-$3}
CONSUMER_PASSWORD=${CONSUMER_PASSWORD:-$4}
SECURITY_TOKEN=${SECURITY_TOKEN:-$5}
SALESFORCE_INSTANCE=${SALESFORCE_INSTANCE:-"https://login.salesforce.com"}
if [ -z "$SALESFORCE_USERNAME" ]
then
logerror "SALESFORCE_USERNAME is not set. Export it as environment variable or pass it as argument"
exit 1
fi
if [ -z "$SALESFORCE_PASSWORD" ]
then
logerror "SALESFORCE_PASSWORD is not set. Export it as environment variable or pass it as argument"
exit 1
fi
if [ -z "$CONSUMER_KEY" ]
then
logerror "CONSUMER_KEY is not set. Export it as environment variable or pass it as argument"
exit 1
fi
if [ -z "$CONSUMER_PASSWORD" ]
then
logerror "CONSUMER_PASSWORD is not set. Export it as environment variable or pass it as argument"
exit 1
fi
if [ -z "$SECURITY_TOKEN" ]
then
logerror "SECURITY_TOKEN is not set. Export it as environment variable or pass it as argument"
exit 1
fi
${DIR}/../../environment/plaintext/start.sh "${PWD}/docker-compose.plaintext.yml"
log "Login with sfdx CLI"
docker exec sfdx-cli sh -c "sfdx sfpowerkit:auth:login -u \"$SALESFORCE_USERNAME\" -p \"$SALESFORCE_PASSWORD\" -r \"$SALESFORCE_INSTANCE\" -s \"$SECURITY_TOKEN\""
log "Send Platform Events"
docker exec sfdx-cli sh -c "sfdx force:apex:execute -u \"$SALESFORCE_USERNAME\" -f \"/tmp/event.apex\""
log "Creating Salesforce Platform Events Source connector"
curl -X PUT \
-H "Content-Type: application/json" \
--data '{
"connector.class": "io.confluent.salesforce.SalesforcePlatformEventSourceConnector",
"kafka.topic": "sfdc-platform-events",
"tasks.max": "1",
"curl.logging": "true",
"salesforce.platform.event.name" : "MyPlatformEvent__e",
"salesforce.instance" : "'"$SALESFORCE_INSTANCE"'",
"salesforce.username" : "'"$SALESFORCE_USERNAME"'",
"salesforce.password" : "'"$SALESFORCE_PASSWORD"'",
"salesforce.password.token" : "'"$SECURITY_TOKEN"'",
"salesforce.consumer.key" : "'"$CONSUMER_KEY"'",
"salesforce.consumer.secret" : "'"$CONSUMER_PASSWORD"'",
"salesforce.initial.start" : "all",
"key.converter": "org.apache.kafka.connect.json.JsonConverter",
"value.converter": "org.apache.kafka.connect.json.JsonConverter",
"confluent.license": "",
"confluent.topic.bootstrap.servers": "broker:9092",
"confluent.topic.replication.factor": "1"
}' \
http://localhost:8083/connectors/salesforce-platform-events-source/config | jq .
sleep 10
log "Verify we have received the data in sfdc-platform-events topic"
timeout 60 docker exec broker kafka-console-consumer -bootstrap-server broker:9092 --topic sfdc-platform-events --from-beginning --max-messages 2