JMS consumer with ActiveMQ network of brokers - java

I have a JMS topic on an ActiveMQ network of brokers cluster (aka distributed topic). I have an external JMS consumer (Weblogic portal) that needs to subscribe to this topic and get all the messages sent to it (across all brokers).
If the consumer subscribes to the topic on one of the brokers, it will only get the subset of the messages that the broker receives, correct?
I guess I could create a consumer for each broker and aggregate the messages together, but then I'm also on the hook for dealing with connection issues and needing to know which brokers are available, etc.
Question, is there a way to configure the network of brokers or consumer to get all the messages from a distributed JMS topic?

If the consumer subscribes to the
topic on one of the brokers, it will
only get the subset of the messages
that the broker receives, correct?
Technically, yes, but the broker network is responsible for knowing which consumers are interested in which messages, and making sure that the right brokers get the right messages.
Normally, this means that every broker gets every message, but if a broker only has consumers with a given message selector, it will only get messages that those clients are interested in.
In practise, this means you pick a broker, connect to it, and let the broker network sort it out amongst themselves. In theory.

You just connect to the cluster. It is up to the cluster to deliver the messages to the consumer.

Related

JMS message re-delivery

I have a queue with one producer and two consumers using CLIENT_ACKNOWLEDGE. The two consumers share the connections, but they live in different threads so each uses its own session.
What happens if consumer A does not acknowledge the last message received? In which scenario the message will be re-delivered and consumed by consumer B? Is it when the session consumer A is using is closed? Do I need some configuration on JMS provider to dictate what happens in such a scenario?
I don't think this situation is directly addressed in the JMS specification so the answer will ultimately depend on what JMS broker you're using. However, having worked on multiple JMS brokers in the past I would say that generally speaking any message that has been dispatched by the broker to a consumer but which hasn't yet been acknowledged by that consumer will be cancelled back to the broker and will be made available for redelivery once the consumer in question is closed.

ActiveMQ clustered topics and fail safety from producer point of view

I want to setup multiple JMS nodes (brokers) which have multiple topics. Recently I discovered failover feature (http://activemq.apache.org/failover-transport-reference.html#FailoverTransportReference-BrokersideOptionsforFailover) which allows consumers to be distributed among all the broker nodes + redirects in case if target node failed.
I'm new to JMS and to ActiveMQ and perhaps my question would sound stupidly, but anyway:
I wonder if ActiveMQ supports distributed Topics from producer point of view so when producer publishes the message then it appears in a cluster rather than in a single cluster node (to where producer publishes it). The reason why I'm interested in this kind of feature is because I'm afraid that if this single node (where producer publishes message) fails, then producer will not be able to publish messages until this node is up again. But it would be much more reliable if producer could publish a message to a cluster (just as producer uses failover feature) and if the original topic holder node is down, then message is just redirected to other broker nodes. I've been looking for some examples and was unable to find them. Could anybody give a hint if ActiveMQ supports this kind of feature? Thanks
Yes, you combine the failover: scheme to provide client-side recovery and then use the network-of-broker on the server-side to distribute the messages to other consumers in the cluster.

How to find number of total consumers/listener on remote ActiveMQ queue

I have one queue I.e. FastAutomationBus. Now I want to find out how many consures/listerner are listening msg in that queue?
You can use consumer advisories . Advisory messages can be thought as some kind of administrative channel where you receive information regarding what is happening on your JMS provider along with what's happening with producers, consumers and destinations.
You can also use JMX to monitor and control the behaviour of the broker.
You can find same in AMQ Management console, there is a tab called Consumers, where it lists all listeners tagged to a particular queue/topic.
You can find IP address and creation time of listener.

ActiveMQ/HornetQ p2p is polling-based or pushing-based model

What happens behind the scene, when receiving messages with (spring or ejb) message listener container in ActiveMQ/HornetQ?
Does broker pushing messages to consumers? If so, how consumers register
themselves to broker?
Or consumers polling messages on the queue? If so, why each queue (in admin console) has a consumer-number field that shows number of registered consumers of the queue?
This link of O'Reilly book said:
The p2p messaging model has traditionally been a pull- or
polling-based model, where messages are requested from the queue
instead of being pushed to the client automatically. (The JMS
specification does not specifically state how the p2p and pub/sub
models must be implemented. Either one may use push or pull, but at
least conceptually pub/sub is push and p2p is pull).
You are not stating the protocol, since ActiveMQ and HornetQ are multi protocol brokers the exact implementation may vary a bit. However, most protocols except HTTP/REST based ones pushes messages to the client. It's not possible to achive high throughput without a push strategy on the wire protocol level.
The application level API allows for "polling", i.e. JMS MessageConsumer.receive, but that's really just a "sleep until a message is pushed" mechanism.

Reducing network hops with a distributed topic with ActiveMQ network of brokers

Lets say I have a network of brokers which share a topic on which orders are published. I have two brokers one in location A and one in location B.
One of the consumers of the topic is also located in location A and is configured to connect to broker A. Both the brokers publish orders on the topic and the consumer will receive all the orders published by the two brokers.
As I understand the orders published by broker in location B will internally be passed to broker in location A by ActiveMQ and from there will be published to the consumer in location A.
Is there an easy way to publish the order from broker B directly to the consumers in location A?
Yes - don't use a network of brokers; what you're describing is how that works (and is designed to work).
If you don't want that, instead have the consumer connect to all brokers directly and don't set them up as a network / cluster.

Categories