Shuttle ESB (4) -- Introduction to publish and subscribe mode instances (1)

Source: Internet
Author: User
Tags msmq

Previously, I have used three articles to explain the introduction instances and macro concepts of shuttle ESB. Shuttle ESB has two message sending modes: Request/corresponding mode and pub/sub mode.


For the distinction between the two modes, see the following article:Shuttle ESB (III)-architecture model introduction (2)


In the first article of shuttle ESB, the introduction to entry instances is a request response mode based on Command commands. Messages sent in this mode are relatively simple and synchronized. The behavior coupling between the sending and receiving ends is large. After the request is sent, other processes will be in the waiting status. After the server returns the response information, the client will perform other actions.


PS: The command mode and pub/sub mode of shuttle ESB are similar to the P2P and pub/sub modes in EJB.


However, the pub/sub mode fully decouples the message publishing end and the subscription end. After sending a message, the pub does not have to wait for the message to return. You can choose to continue sending or stop sending the message. To receive a message, the receiver only needs to subscribe to the event message.

When we actually use shuttle ESB in a project, we usually use the pub/sub mode. Next, we will explain this mode.


Note: Even the command-based request/corresponding mode can be implemented by publishing and subscription.


Currently, shuttle ESB only supports three Queues: Microsoft Message Queue MSMQ, sqlserver table-based queue, and rabbit MSMQ. The pub/sub mode of shuttle ESB requires MSMQ and sqlserver to be implemented based on two types of Message Queues: Table queue.


For SQL Server table-based queues, we may all have doubts: Does the use of SQL Server databases limit the applicability of shuttle ESB?

You don't have to worry about it. The core components of the shuttle ESB are not based on any third-party components. In the future, it will certainly support MySQL, Oracle, or other databases. Currently, Eben is not familiar with Oracle because it has not used Oracle, so Oracle-Based Queue implementation is not implemented. Of course, he mentioned it many times and hoped that I would make some contributions to the open-source community and contribute some code to him on GitHub. However, this implementation is not a matter of one day or two days. I have no time to study it. This time is too short. I have to consider livelihood issues! You have to survive and consider making contributions! After a year, let's talk about it.


Let's continue to introduce the demo implementation based on the pub/sub mode. Simple functions:

A message event ordercompletedevent is published from pub on the message publishing end. Multiple Clients (such as Suba and subb) subscribe to this event ordercompletedevent. After pub publishes a message, Suba and subb can receive the ordercompletedevent message.

After receiving messages, Suba and subb process the messages as needed. Then they will publish a workdoneevent event message. This time, the server subscribes to the workdoneevent message. After a workdoneevent message is published by Suba and subb, pub can receive the workdoneevent message.


PS: Why are two different messages used by the message publishing end and subscription end? If the same message is used, the above implementation will form an endless loop. The reason is that after the shuttle ESB instance is started, the instance will listen to one or more given message queues. If the publisher and subscription listen to one queue, an endless loop is formed.


The following describes how to prepare development instances.


1. Install Message Queue: MSMQ

For specific installation instructions, see:Shuttle ESB (1): Getting Started instance


2. Create a database and initialize a database table queue

Create a database in sqlserver: Shuttle (you can customize the database name ). Then run "{root} \ shuttle. ESB \ source \ shuttle. ESB. sqlserver \ scripts \ subscriptionmanagercreate. SQL script (in the source code, this script is provided in this example) to create and initialize the sqlserver table queue.


3. Install the nuget plugin

It is a plug-in for managing third-party DLL. I will not detail the installation and use of nuget on the Internet. You can use Baidu.


For more information, see the next article.

Shuttle ESB (4) -- Introduction to publish and subscribe mode instances (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.