Mike Stoddart
Mike Stoddart

Reputation: 506

How to route messages to specific clients using ActiveMQ?

I want to run a Java based message broker that will route messages to web clients. Web client connections are handled on our server using our custom Java websocket code, which authenticates users against the user database.

I think my server side websocket handler code would connect to ActiveMQ and perform subscription management via AQMP.

I have a specific requirement however:

Note that I don't need to retain messages if a client is not connected. Messages are being used to inform the web client applications of actions they need to take.

I'm considering ActiveMQ but I was hoping people with experience of the product could clarify if it supports this requirement?

If ActiveMQ isn't the best option, could you recommend something else?

Thanks

Upvotes: 0

Views: 171

Answers (1)

Matt Pavlovich
Matt Pavlovich

Reputation: 4316

Yes, ActiveMQ is a great choice for this.

As far as specific approach goes, it depends on your data model and message flow. You have several options, including:

  1. Produce and consume to a topic-per-client a. Messages for Client ABC go to topic://CLIENTS.ABC, for Client XYZ go to topic://CLIENTS.XYZ, and the subscribers connect accordingly.

  2. Produce a message with a header and use a consumer-side selector (aka 'filters' in AMQP) to filter messages on a per-client basis. (abc client subscribes to-- ClientId = ABC, xyz client subscribe to-- ClientId = XYZ)

When using WebSockets, you might also look to STOMP which is text-based protocol. (Just depends on your programming language and available libraries that you had in mind)

Upvotes: 1

Related Questions