Using a message broker with end user clients directly

夙愿已清 提交于 2019-12-24 23:06:15

问题


I want to find a way to implement push messages from a server to multiple end user clients with the same message.

One of the options I found was to use a message broker and use it to implement the pub/sub pattern. What I'm not sure about is what supposed to be considered a consumer in such a scenario.

What I thought that the general architecture is when using a message broker is:

End user clients <----> Message broker <---> Server (The clients and server can also speak to one another on things that are not related to topic messages)

And the process I at least thought that is supposed to happen is this:

1) The end user client registers to a specific topic by sending an initial message directly to the message broker.

2) The server got a message about a topic which he wants every end user will get, so it adds a message to the topic.

3) The message broker instantly sends the message to all the end users by itself without the usage of other push message services like SignalR, Pusher etc. (without the usage of them meaning that it might use it behind the scene, but the developer doesn't actually program the sending of the messages).

After that I heard that the consumer is not supposed to be end user clients, but other servers?

Is my description of the process correct? Or is it something else?


回答1:


The pub/sub pattern does sound like what you want. However, there are some points which need clarification.

The first concept you need to clear up is that of a client and a server interacting with the message broker. From the perspective of the message broker everything that connects to it is a client. In general, the clients can produce messages and/or consume messages; that's it. Whether or not your applications are acting as clients or servers in some other capacity in your overall architecture is irrelevant as it relates to the message broker.

Here is a clarified summary using your 3-step process:

  1. One or more clients create a consumer (sometimes called a "subscriber") on a topic they care about.
  2. One or more clients produce messages to that topic to, for example, inform the consumers/subscribers about some event.
  3. The broker dispatches the message to every registered consumer/subscriber.

All this work is done exclusively via the messaging client implementation. In other words, the client applications only need to use the messaging client implementation (e.g. AMQP client, STOMP client, etc.). The broker itself will dispatch the actual message to the consumers/subscribers whether that be through some kind of asynchronous "listener" or a synchronous method invocation to receive the message. This is considered basic messaging functionality. There is no need for the client application to use any kind of additional library (e.g. SignalR or Pusher) to fetch the message from the broker or to push the message from the broker to the client.



来源:https://stackoverflow.com/questions/58082513/using-a-message-broker-with-end-user-clients-directly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!