This sample demonstrates how to use the core features of Windows Azure AppFabric Service Bus to achieve typical PublishSubscribe scenarios. See the Service Bus documentation for more information about the Service Bus before exploring the samples.
This sample covers the basic features in 4 distinct steps. These steps demonstrate the use of Queues, Topics, Subscriptions, Rules / Actions and Sessions.
Prerequisites
If you haven't already done so, please read the release notes document that explains how to sign up for a Windows Azure AppFabric account and how to configure your environment.
Sample Flow
The sample flows in the following manner:
- Temporal decoupling thru use of Queues
- Single publisher with multiple consumers thru Topics and Subscriptions
- Use of Rules and Actions to filter messages and stamp certain properties
- Use of Sessions to logically group messages
Running the Sample
To run the sample:
- Assuming you installed this in a C# console application, you can simply run the Microsoft.Samples.PublishSubscribe.Program.Start() method in your Main() method call.
- Build the solution in Visual Studio and run the sample project.
- When prompted enter following information:
- ServiceBus namespace;
- ServiceBus issuer name;
- And ServiceBus issuer key.
Expected Output - Queue Demo
Welcome to the Queue demo. Here we will show a simple temporal decoupling pattern using a Queue. Press ENTER to start. Creating Queue... Now sending messages to the Queue. Message sent: Package lost, 835080e4a54a4da49d44cc4fb07b8c7b Message sent: Package damaged, f061f13a38df49358dd741c2854a0753 Message sent: Product defective, 3aee03ca7ef1456fa6298f8d03b1cded Message sent: Product damaged, a17b53faf6b9431086e702538a45d5d0 Message sent: Package lost, 67f47497a1b4422ca64547af7ef32670 Message sent: Package lost, dc14d0ab689f4751bfe00e9ddd7fce7b Now receiving messages from Queue. Message received: 1, Package lost, 835080e4a54a4da49d44cc4fb07b8c7b Processing message (sleeping...) Message received: 2, Package damaged, f061f13a38df49358dd741c2854a0753 Processing message (sleeping...) Message received: 3, Product defective, 3aee03ca7ef1456fa6298f8d03b1cded Processing message (sleeping...) Message received: 4, Product damaged, a17b53faf6b9431086e702538a45d5d0 Processing message (sleeping...) Message received: 5, Package lost, 67f47497a1b4422ca64547af7ef32670 Processing message (sleeping...) Message received: 6, Package lost, dc14d0ab689f4751bfe00e9ddd7fce7b Processing message (sleeping...) End of scenario, press ENTER to continue. |
Expected Output - Publish/Subscribe Demo
Welcome to the PubSub demo. Here we will send messages to a Topic with two subscrptions. Press ENTER to start. Creating Topic... Creating Subscriptions... Now sending messages to Topic. Message sent: Package lost, 835080e4a54a4da49d44cc4fb07b8c7b Message sent: Package damaged, f061f13a38df49358dd741c2854a0753 Message sent: Product defective, 3aee03ca7ef1456fa6298f8d03b1cded Message sent: Product damaged, a17b53faf6b9431086e702538a45d5d0 Message sent: Package lost, 67f47497a1b4422ca64547af7ef32670 Message sent: Package lost, dc14d0ab689f4751bfe00e9ddd7fce7b Message sent: Package damaged, da82041af71e4d5a9e6d2bdc4cf4b0fc Message sent: Product defective, 0b92e57ecd154a8da887a1992f3431f3 Message sent: Product damaged, 3332982ee6564f42a31c075207d6bcd3 Message sent: Package lost, 3cba8ff3d8434619a55bf99ca377c42e Message sent: Package damaged, a6405033816a4873837e22fdb0c75ed5 Message sent: Product defective, b37753adb8484cc9af6896bfc9027bc9 Message sent: Package lost, 3e2c24ee82a241aaa9bc80680366c09c Message sent: Package damaged, 51afa29326a24cbcb7890b79557c2fc7 Message sent: Product defective, 1564ddcc079440d487e97e6458e56da4 Now receiving messages from AgentSubscription.. Message received (AgentSubscription): 1, Package lost, 835080e4a54a4da49d44cc4fb07b8c7b Message received (AgentSubscription): 2, Package damaged, f061f13a38df49358dd741c2854a0753 Message received (AgentSubscription): 3, Product defective, 3aee03ca7ef1456fa6298f8d03b1cded Message received (AgentSubscription): 4, Product damaged, a17b53faf6b9431086e702538a45d5d0 Message received (AgentSubscription): 5, Package lost, 67f47497a1b4422ca64547af7ef32670 Message received (AgentSubscription): 6, Package lost, dc14d0ab689f4751bfe00e9ddd7fce7b Message received (AgentSubscription): 7, Package damaged, da82041af71e4d5a9e6d2bdc4cf4b0fc Message received (AgentSubscription): 8, Product defective, 0b92e57ecd154a8da887a1992f3431f3 Message received (AgentSubscription): 9, Product damaged, 3332982ee6564f42a31c075207d6bcd3 Message received (AgentSubscription): 10, Package lost, 3cba8ff3d8434619a55bf99ca377c42e Message received (AgentSubscription): 11, Package damaged, a6405033816a4873837e22fdb0c75ed5 Message received (AgentSubscription): 12, Product defective, b37753adb8484cc9af6896bfc9027bc9 Message received (AgentSubscription): 13, Package lost, 3e2c24ee82a241aaa9bc80680366c09c Message received (AgentSubscription): 14, Package damaged, 51afa29326a24cbcb7890b79557c2fc7 Message received (AgentSubscription): 15, Product defective, 1564ddcc079440d487e97e6458e56da4 Now receiving messages from AuditSubscription.. Message received (AuditSubscription): 1, Package lost, 835080e4a54a4da49d44cc4fb07b8c7b Message received (AuditSubscription): 2, Package damaged, f061f13a38df49358dd741c2854a0753 Message received (AuditSubscription): 3, Product defective, 3aee03ca7ef1456fa6298f8d03b1cded Message received (AuditSubscription): 4, Product damaged, a17b53faf6b9431086e702538a45d5d0 Message received (AuditSubscription): 5, Package lost, 67f47497a1b4422ca64547af7ef32670 Message received (AuditSubscription): 6, Package lost, dc14d0ab689f4751bfe00e9ddd7fce7b Message received (AuditSubscription): 7, Package damaged, da82041af71e4d5a9e6d2bdc4cf4b0fc Message received (AuditSubscription): 8, Product defective, 0b92e57ecd154a8da887a1992f3431f3 Message received (AuditSubscription): 9, Product damaged, 3332982ee6564f42a31c075207d6bcd3 Message received (AuditSubscription): 10, Package lost, 3cba8ff3d8434619a55bf99ca377c42e Message received (AuditSubscription): 11, Package damaged, a6405033816a4873837e22fdb0c75ed5 Message received (AuditSubscription): 12, Product defective, b37753adb8484cc9af6896bfc9027bc9 Message received (AuditSubscription): 13, Package lost, 3e2c24ee82a241aaa9bc80680366c09c Message received (AuditSubscription): 14, Package damaged, 51afa29326a24cbcb7890b79557c2fc7 Message received (AuditSubscription): 15, Product defective, 1564ddcc079440d487e97e6458e56da4 End of scenario, press ENTER to continue. |
Expected Output - Topic/Rules Demo
Welcome to the Topic / Rules demo. Here we will stamp messages with new properties based on their content. Press ENTER to start. Creating Topic... Sending messages to Topic. Sent values: SupportPackage=Basic, Severity=1, Priority=5. Sent values: SupportPackage=Basic, Severity=1, Priority=5. Sent values: SupportPackage=Premium, Severity=2, Priority=5. Sent values: SupportPackage=Premium, Severity=2, Priority=5. Sent values: SupportPackage=Basic, Severity=2, Priority=5. Sent values: SupportPackage=Basic, Severity=2, Priority=5. Sent values: SupportPackage=Premium, Severity=3, Priority=5. Sent values: SupportPackage=Premium, Severity=3, Priority=5. Sent values: SupportPackage=Premium, Severity=3, Priority=5. Sent values: SupportPackage=Basic, Severity=3, Priority=5. Sent values: SupportPackage=Basic, Severity=4, Priority=5. Sent values: SupportPackage=Basic, Severity=4, Priority=5. Sent values: SupportPackage=Basic, Severity=4, Priority=5. Sent values: SupportPackage=Premium, Severity=5, Priority=5. Sent values: SupportPackage=Premium, Severity=5, Priority=5. Receiving filtered messages with added property value for Importance. Received values: SupportPackage:Basic, Severity:1, Priority:1, Importance:High Received values: SupportPackage:Basic, Severity:1, Priority:1, Importance:High Received values: SupportPackage:Premium, Severity:2, Priority:1, Importance:High Received values: SupportPackage:Premium, Severity:2, Priority:1, Importance:High Received values: SupportPackage:Premium, Severity:3, Priority:1, Importance:High Received values: SupportPackage:Premium, Severity:3, Priority:1, Importance:High Received values: SupportPackage:Premium, Severity:3, Priority:1, Importance:High Received values: SupportPackage:Premium, Severity:5, Priority:1, Importance:High Received values: SupportPackage:Premium, Severity:5, Priority:1, Importance:High End of scenario, press ENTER to continue. |
Expected Output - Topic/Sessions Demo
Welcome to the Topic / Sessions demo. Press ENTER to start. Creating Topic... Now sending messages to Topic. Issue properties: Title=Package lost, Category=1. Issue properties: Title=Package damaged, Category=1. Issue properties: Title=Product defective, Category=2. Issue properties: Title=Product damaged, Category=2. Issue properties: Title=Package lost, Category=2. Issue properties: Title=Package lost, Category=2. Issue properties: Title=Package damaged, Category=7. Issue properties: Title=Product defective, Category=2. Issue properties: Title=Product damaged, Category=6. Issue properties: Title=Package lost, Category=8. Issue properties: Title=Package damaged, Category=4. Issue properties: Title=Product defective, Category=4. Issue properties: Title=Package lost, Category=8. Issue properties: Title=Package damaged, Category=7. Issue properties: Title=Product defective, Category=2. Now recieving messages from Subscription. Message recieved for Category1: Package lost Message recieved for Category1: Package damaged Message recieved for Category2: Product defective Message recieved for Category2: Product damaged Message recieved for Category2: Package lost Message recieved for Category2: Package lost Message recieved for Category2: Product defective Message recieved for Category2: Product defective End of scenario, press ENTER to continue. |