Skip to content

Commit

Permalink
add README.adoc for servicebus queue multibinders sample (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiliuTo authored May 1, 2020
1 parent 83ddc66 commit c856ec1
Showing 1 changed file with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
= Spring Cloud Azure Stream Binder for Multiple Service Bus Namespaces Code Sample

This code sample demonstrates how to use the Spring Cloud Stream Binder for multiple Azure Service Bus namespaces.
In this sample you will bind to two Service Bus namespaces separately through two queue binders.
The sample app exposes REST APIs to receive string message. Then message is sent through Azure
Service Bus to a `sink` which simply logs the message.

Running this sample will be charged by Azure. You can check the usage and bill at https://azure.microsoft.com/en-us/account/[this link].

== Connection string based usage

1. Create two queues in different Service Bus namespaces. Please refer to https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-create-namespace-portal[Azure Service Bus].

2. Update link:src/main/resources/application.properties[application.properties]

+

[source%nowrap, properties]
....
# Configuration for default binder. Currently, the limitation is default binder must be provided
# Fill the first Service Bus namespace connection string copied from portal
spring.cloud.azure.servicebus.connection-string=[servicebus-namespace-1-connection-string]
# Configuration for another binder
spring.cloud.stream.binders.servicebus2.type=servicebus-queue
# Set defaultCandidate to false
spring.cloud.stream.binders.servicebus2.defaultCandidate=false
spring.cloud.stream.binders.servicebus2.environment.spring.cloud.azure.servicebus.connection-string=[servicebus-namespace-2-connection-string]
....

[NOTE]
====
The *defaultCandidate* configuration item:
Whether the binder configuration is a candidate for being considered a default binder, or can be used only when explicitly referenced. This allows adding binder configurations without interfering with the default processing.
====


== How to run
1. Update stream binding related properties in link:src/main/resources/application.properties[application.properties]

+
[source%nowrap, properties]
....
spring.cloud.stream.bindings.input.destination=[servicebus-queue-1-name]
spring.cloud.stream.bindings.output.destination=[servicebus-queue-name-same-as-above]
spring.cloud.stream.bindings.input1.destination=[servicebus-queue-2-name]
spring.cloud.stream.bindings.output1.destination=[servicebus-queue-name-same-as-above]
....

2. Run the `mvn clean spring-boot:run` in the root of the code sample to get the app running.

3. Send a POST request to test the default binder
+
....
$ curl -X POST http://localhost:8080/messages?message=hello
....
+

4. Verify in your app's logs that a similar message was posted:
+
....
[1] New message received: 'hello'
[1] Message 'hello' successfully checkpointed
....

5. Send another POST request to test the other binder
+
....
$ curl -X POST http://localhost:8080/messages1?message=hello
....
+

6. Verify in your app's logs that a similar message was posted:
+
....
[2] New message received: 'hello'
[2] Message 'hello' successfully checkpointed
....

5. Delete the resources on http://ms.portal.azure.com/[Azure Portal] to avoid unexpected charges.

0 comments on commit c856ec1

Please sign in to comment.