Skip to content

Commit

Permalink
convert output to use heredoc approach
Browse files Browse the repository at this point in the history
  • Loading branch information
davegarvey committed Dec 31, 2024
1 parent 4cdad8d commit 3c7c8f1
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
echo "Streams - Authenticated PubSub"
echo "Part 1: Authenticate as a subscriber"
echo "This script connects to a server-sent event endpoint, and waits to receive messages. It authenticates using the Authorization header."
echo "Use script 2 to send messages, then check back here to see them being received."
cat <<EOF
$(printf "\033[1mStreams - Authenticated PubSub\033[0m")
Part 1: Authenticate as a subscriber
This script connects to a server-sent event endpoint, and waits to receive messages. It authenticates using the Authorization header.
Now use script 2 to send messages, then check back here to see them being received.
Waiting for messages... (press Ctrl+C to stop)
EOF

curl http://tyk-gateway.localhost:8080/streams-authenticated-pubsub/sse \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicG9sIjoiNjZmZmI5OTMyYTRhNTEwMDAxODZkMzc0IiwiaWF0IjoxNTE2MjM5MDIyfQ.G_rM5NWQIQopOZABTLkZEfnp2XSAiN5vFyRZAOWbtFs'
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
echo "Streams - Authenticated PubSub"
echo "Part 2: Authenticate as a publisher"
echo "This script sends messages to the clients connected in script 1 - check its terminal to see the messages received."
cat <<EOF
$(printf "\033[1mStreams - Authenticated PubSub\033[0m")
Part 2: Authenticate as a publisher
This script sends messages to the clients connected in script 1.
Now check terminal 1 to see the messages received.
EOF

curl http://tyk-gateway.localhost:8080/streams-authenticated-pubsub/post \
-d 'Hello, Tyk streams!' \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
echo "Streams - Authenticated PubSub"
echo "Part 3: Authentication failure"
echo "This script attempts to send an unauthenticated message to the auth-protected endpoint. This results in the request being rejected."
cat <<EOF
$(printf "\033[1mStreams - Authenticated PubSub\033[0m")
Part 3: Authentication failure
This script attempts to send an unauthenticated message to the auth-protected endpoint. This results in the request being rejected.
EOF

curl http://tyk-gateway.localhost:8080/streams-authenticated-pubsub/post \
-d 'Hello, Tyk streams!'
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ source scripts/common.sh

check_for_wscat

echo "Streams - Bidirectional"
echo "Part 1: Listen for events based for 'dev1'"
echo "This example uses kafka and Tyk context data to dynamically deliver messages based on the input."
echo "This part connects to a websocket as user 'dev1' and waits to receive messages for the user."
echo "Now run part two in a different terminal, to connect as 'dev2'."
cat <<EOF
$(printf "\033[1mStreams - Bidirectional\033[0m")
Part 1: Listen for events based for 'dev1'
This example uses kafka and Tyk context data to dynamically deliver messages based on the input.
This part connects to a websocket as user 'dev1' and waits to receive messages for the user.
Now run part 2 in a different terminal, to connect as 'dev2'.
EOF

wscat -c http://localhost:8080/streams-bidirectional/ws\?user\=dev1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ source scripts/common.sh

check_for_wscat

echo "Streams - Bidirectional"
echo "Part 2: Listen for events based for 'dev2'"
echo "Now run part three in a different terminal, to send a message to 'dev1'."
cat <<EOF
$(printf "\033[1mStreams - Bidirectional\033[0m")
Part 2: Listen for events based for 'dev2'
Now run part 3 in a different terminal, to send a message to 'dev1'.
EOF

wscat -c http://localhost:8080/streams-bidirectional/ws\?user\=dev2
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
echo "Streams - Bidirectional"
echo "Part 3: Send a message to 'dev1'"
echo "This part posts data to the stream via Tyk. The data is processed and delivered to the user defined in the querystring."
echo "Check terminals one and two, only the first terminal ('dev1') will have received the message."
cat <<EOF
$(printf "\033[1mStreams - Bidirectional\033[0m")
Part 3: Send a message to 'dev1'
This part posts data to the stream via Tyk. The data is processed and delivered to the user defined in the querystring.
Now check the first and second terminals, only the first terminal ('dev1') will have received the message.
EOF

curl -X POST http://localhost:8080/streams-bidirectional/event\?user\=dev1 -d '{"foo": "bar"}'
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
echo "Streams - Bidirectional"
echo "Part 4: Send a message to 'dev2'"
echo "Same as part 3, but message is sent to 'dev2'"
echo "Check terminals one and two, only the second terminal ('dev2') will have received the message."
cat <<EOF
$(printf "\033[1mStreams - Bidirectional\033[0m")
Part 4: Send a message to 'dev2'
Same as part 3, but message is sent to 'dev2'
Now check the first and second terminals, only the second terminal ('dev2') will have received the message.
EOF

curl -X POST http://localhost:8080/streams-bidirectional/event\?user\=dev2 -d '{"Tyk": "Streams"}'
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
echo "Streams - HTTP to AMQP"
echo "Part 1: Listen for messages"
echo "Once connected, run part two of this example in a different terminal. The messages sent by part 2 will appear here."
echo "Tyk enables messages in am AMQP queue to be consumed using server-sent events."
echo "Connecting to the SSE endpoint..."
cat <<EOF
$(printf "\033[1mStreams - HTTP to AMQP\033[0m")
Part 1: Listen for messages
Once connected, run part 2 of this example in a different terminal. The messages sent by part 2 will appear here.
Tyk enables messages in an AMQP queue to be consumed using server-sent events.
Waiting for messages... (Ctrl+C to stop)
EOF

curl -N http://tyk-gateway.localhost:8080/streams-http-to-amqp/sse
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
echo "Streams - HTTP to AMQP"
echo "Part 2: Send a message"
echo "Each time this script is run, the message 'Hello, Tyk Streams!' is sent via the message broker, RabbitMQ."
echo "Tyk converts the HTTP POST request into an AMQP publish message, which is then placed in the RabbitMQ message queue."
echo "Check part 1 to see that the message is received."
cat <<EOF
$(printf "\033[1mStreams - HTTP to AMQP\033[0m")
Part 2: Send a message
Each time this script is run, the message 'Hello, Tyk Streams!' is sent via the message broker, RabbitMQ.
Tyk converts the HTTP POST request into an AMQP publish message, which is then placed in the RabbitMQ message queue.
Now check the first terminal to see that the message is received.
EOF

curl -X POST http://tyk-gateway.localhost:8080/streams-http-to-amqp/post -d '{"message": "Hello, Tyk Streams!"}' -H "Content-Type: application/json"
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
echo "Streams - HTTP to Kakfa"
echo "Part 1: Consume a Kafka topic via the Kafka console consumer"
echo "This example connects to the 'tyk-streams-example' Kafka topic directly using the standard Kafka console consumer."
echo "Now run part two in a different terminal, to connect to Kafka using Tyk Streams."
cat <<EOF
$(printf "\033[1mStreams - HTTP to Kakfa\033[0m")
Part 1: Consume a Kafka topic via the Kafka console consumer
This example connects to the 'tyk-streams-example' Kafka topic directly using the standard Kafka console consumer.
Now run part 2 in a different terminal, to connect to Kafka using Tyk Streams.
Waiting for messages... (Ctrl+C to stop)
EOF

docker exec -it tyk-demo-kafka-1 /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic tyk-streams-example --from-beginning
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
echo "Streams - HTTP to Kakfa"
echo "Part 2: Consumer a Kafka topic via Tyk Streams server sent events"
echo "This example connects to Kafka via a Tyk Streams endpoint, which delivers the messages via server-sent events."
echo "Now run part three of this example in a different terminal, to see the message appear here."
cat <<EOF
$(printf "\033[1mStreams - HTTP to Kakfa\033[0m")
Part 2: Consumer a Kafka topic via Tyk Streams server sent events
This example connects to Kafka via a Tyk Streams endpoint, which delivers the messages via server-sent events.
Now run part 3 of this example in a different terminal, to see the message appear here.
Waiting for messages... (Ctrl+C to stop)
EOF

curl http://tyk-gateway.localhost:8080/streams-http-to-kafka/sub
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
echo "Streams - HTTP to Kakfa"
echo "Part 3: Send messages to the Kafka topic via HTTP"
echo "This sends a messages to the 'tyk-streams-example' Kafka topic via an HTTP request that is handled by Tyk."
echo "Now check the first and second terminals to see that the message 'Hello, Tyk Streams!' has appeared."
cat <<EOF
$(printf "\033[1mStreams - HTTP to Kakfa\033[0m")
Part 3: Send messages to the Kafka topic via HTTP
This sends a messages to the 'tyk-streams-example' Kafka topic via an HTTP request that is handled by Tyk.
Now check the first and second terminals to see that the message 'Hello, Tyk Streams!' has appeared.
EOF

curl -X POST http://tyk-gateway.localhost:8080/streams-http-to-kafka/post -d 'Hello, Tyk Streams!'
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
echo "Streams - HTTP to Redis Pub/Sub"
echo "Part 1: Listening to a Redis Channel"
echo "Once connected, run part two of this example in a different terminal. The messages sent will appear here."
echo "Connecting to the Redis channel..."
cat <<EOF
$(printf "\033[1mStreams - HTTP to Redis Pub/Sub\033[0m")
Part 1: Listening to a Redis Channel
Once connected, run part two of this example in a different terminal. The messages sent will appear here.
Connecting to the Redis channel...
EOF

docker exec tyk-demo-tyk-redis-1 redis-cli SUBSCRIBE streams
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
echo "Streams - HTTP to Redis Pub/Sub"
echo "Part 2: Sending a message"
echo "Each time this script is run, the message \"Hello, Tyk Streams!\" will be received through the Redis channel in part 1. Check the other terminal to see the messages."
cat <<EOF
$(printf "\033[1mStreams - HTTP to Redis Pub/Sub\033[0m")
Part 2: Sending a message
Each time this script is run, the message \"Hello, Tyk Streams!\" will be received through the Redis channel in part 1. Check the other terminal to see the messages.
EOF

curl -d 'Hello, Tyk Streams!' http://tyk-gateway.localhost:8080/streams-http-to-redis-pubsub/post
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ source scripts/common.sh

check_for_wscat

echo "Streams - HTTP to Websocket Example"
echo "Part 1: Listening to a Websocket"
echo "Once connected, run part two of this example in a different terminal. The messages sent will appear here."
echo "Connecting to the websocket..."
cat <<EOF
$(printf "\033[1mStreams - HTTP to Websocket Example\033[0m")
Part 1: Listening to a Websocket
Once connected, run part two of this example in a different terminal. The messages sent will appear here.
Connecting to the websocket...
EOF

wscat -c ws://tyk-gateway.localhost:8080/streams-http-to-websocket/subscribe
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
echo "Streams - HTTP to Websocket Example"
echo "Part 2: Sending a message"
echo "Each time this script is run, the message \"Hello, Tyk Streams!\" will be received through the websocket in part 1. Check the other terminal to see the messages."
cat <<EOF
$(printf "\033[1mStreams - HTTP to Websocket Example\033[0m")
Part 2: Sending a message
Each time this script is run, the message \"Hello, Tyk Streams!\" will be received through the websocket in part 1. Check the other terminal to see the messages.
EOF

curl -d '{"message":"Hello, Tyk Streams!"}' http://tyk-gateway.localhost:8080/streams-http-to-websocket/post

0 comments on commit 3c7c8f1

Please sign in to comment.