Created
March 1, 2025 03:52
-
-
Save johanrhodin/a6d9f6c339ddfd19954727fc12cd3af9 to your computer and use it in GitHub Desktop.
Minimum Viable Exchange Federation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Minimum Viable Exchange Federation | |
| # Upstream servers are the servers towards where messages are originally published | |
| # Downstream servers are where the messages get forwarded to | |
| # Two clusters | |
| CREDS="nbqblhiv:PASSWORD_GOES_HERE" | |
| VHOST="nbqblhiv" | |
| UPSTREAM_URL="amqps://[email protected]/$VHOST" | |
| HTTPS_DOWNSTREAM="https://[email protected]" | |
| HTTPS_UPSTREAM="https://[email protected]" | |
| # 2. Create a federation policy on downstream | |
| curl -i -X PUT -H "Content-Type: application/json" $HTTPS_DOWNSTREAM/api/policies/$VHOST/fedit/ -d '{"pattern":"^myexchange$", "definition": {"federation-upstream-set":"all"}, "priority":0, "apply-to": "exchanges"}' | |
| # Optional: 3. Create queue policy on downstream (matching all queues in the vhost!) | |
| curl -i -X PUT -H "Content-Type: application/json" $HTTPS_DOWNSTREAM/api/policies/$VHOST/maxlen/ -d '{"pattern":".", "definition": {"max-length":10000}, "priority":0, "apply-to": "queues"}' | |
| # 4. Create federation-upstream on downstream | |
| curl -i -X PUT -H "Content-Type:application/json" -d '{"value":{"uri":"'$UPSTREAM_URL'","expires":36000000}}' $HTTPS_DOWNSTREAM/api/parameters/federation-upstream/$VHOST/upstream | |
| # Create 1 queue on both sides | |
| curl -i -X PUT -H "Content-Type: application/json" $HTTPS_DOWNSTREAM/api/queues/$VHOST/q1/ -d '{"auto_delete":false,"durable":true,"arguments":{}}' | |
| curl -i -X PUT -H "Content-Type: application/json" $HTTPS_UPSTREAM/api/queues/$VHOST/q1/ -d '{"auto_delete":false,"durable":true,"arguments":{}}' | |
| # Create 1 exchange on downstream | |
| curl -i -X PUT -H "Content-Type: application/json" -d '{"type":"topic","auto_delete":false,"durable":true,"internal":false}' $HTTPS_DOWNSTREAM/api/exchanges/$VHOST/myexchange/ | |
| # Create bindings from exchange to queues | |
| curl -i -XPOST -H 'Content-Type: application/json' $HTTPS_DOWNSTREAM/api/bindings/$VHOST/e/myexchange/q/q1 -d '{"routing_key":"#"}' | |
| curl -i -XPOST -H 'Content-Type: application/json' $HTTPS_UPSTREAM/api/bindings/$VHOST/e/myexchange/q/q1 -d '{"routing_key":"#"}' | |
| #Publish a message to upstream - will end up on both upstream and downstream | |
| curl -i -X POST -H "Content-Type: text/plain" \ | |
| -d '{"properties":{},"routing_key":"mykey","payload":"my body","payload_encoding":"string"}' \ | |
| "$HTTPS_UPSTREAM/api/exchanges/$VHOST/myexchange/publish" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the record...