In WAS, why TOPIC and QUEUE are used together? - jms

In websphere app server 6.1, when i want to set up JMS, I need to set up a topic, and i need to set up queues and then in MQ explorer I create a subscription between the topic and the queues. Now this configuration is for a publish /subscribe model. If something is published to the topic, all queues will pick up the message.
So how do we do point to point messaging in websphere? I ask this question because I thought topic is for publish subscribe model. And queue is for point to point messaging. But in WAS, the two are mixed up.

The two aren't mixed up. There's no contradiction here, really.
The publish/subscribe model uses a topic (to which "things" are published), and a set of queues that are set to consume that topic.
The point-to-point model uses a queue; the "producing" application puts messages in the queue, and the "consuming" application gets messages from that queue.
Therefore, there's no contradiction. Remember, topics and queues are just "tools" to implement publish/subscribe or point-to-point topologies.

Related

ActiveMQ vs JMS

I am trying to understand JMS.
What is the difference between ActiveMQ and JMS
can pool the data from NON ActiveMQ with ActiveMQ plugin in Spring?
Thanks ,In advance
JMS is a specification. JMS has three main parts to it. The first is the producer, which is nothing more than a bean that submits a "message" to a JMS broker (#2) (the system that manages messages between producers and consumers). In this case, ActiveMQ is the broker. Once the broker receives a message, the consumer (#3), or Message-Driven Bean (MDB), processes the message.
If you want to work with JMS, you'll just write both your producer/consumer code using the JMS API, but behind the scenes there is a "resource adapter" that is a special ActiveMQ driver that will connect to an ActiveMQ instance and do the management for you.
Have a look at this post I made recently. I'm still trying to figure out the best way to write JMS beans, but I've got the basics down.
The accepted answer emphasizes what is the structure of JMS is. Not disagreeing just want to add to it in case anyone else wants to know. ActiveMQ could be a JMS supplier. A JMS supplier shapes the computer program system for encouraging the utilize of JMS concepts interior an application. A single node of ActiveMQ which permits clients to associate to it and utilize these informing concepts is called an "ActiveMQ Broker."
Enterprises feel this disparity with business actions such as mergers and acquisitions. This creates the need to maintain an increasingly heterogeneous collection of business applications. As your enterprise grows, so does the need to allow all of these platforms to share data. A number of architectural patterns exist today which help to solve this problem.
Some other examples of JMS providers are:
HornetQ.
RabbitMQ.
SonicMQ.
Winsows Azure Messaging
The following example shows a simple configuration of an ActiveMQ connection:
<jms:config name="JMS_Config">
<jms:active-mq-connection >
<jms:factory-configuration brokerUrl="tcp://localhost:61616" />
</jms:active-mq-connection>
</jms:config>
This post explains a detailed difference between the ActiveMQ and JMS (or maybe about the details of their specifications). Hope it clears your concepts.

JMS: publisher publishes to queue, subscriber would like to read like it was a topic

I have a JMS publisher, which I cannot change (external system). This publisher publishes messages into some predefined JMS queue. I would like to design a multi-node subscriber system in which all subscribing nodes will receive a copy of each message (in my design, a subscriber node is able to realize if the message is targeted at this node by checking some property inside the message, so only one subscriber node will eventually process the message, while other subscriber nodes will discard their copies).
Changing the publisher system to use Topics could work flawlessly, but I cannot change the publisher.
Currently, I see two options to solve this:
One option which can probably work is to use QueueBrowser, implement periodic polling which will read all messages and if the message is "mine", remove the message from queue and process. This is a huge overhead for such a simple problem.
Another option is to write a dispatcher which subscribes to the queue and dispatches each message to multiple "internal" subscribers (e.g. as explained here: JMS - Going from one to multiple consumers). But this creates bottleneck in the dispatcher killing the whole scalability idea.
A third option is to have multiple "intermediate" queue subscribers, each subscriber, when it receives a message, re-publishes it to a Topic for which the target subscribers will subscribe. This can work, but it's an extra hop in the flow, so not sure if the benefit (scalability) will be worth the loss (latency and complexity).
I wonder if there are any other ideas on how to solve this.
Can I have a subscriber listening to all topics ?
Can I configure JMS (WebLogic in my case) to auto-forward messages from queue to some topic?
Other options?
Thanks.
With the Oracle Service Bus you can route Queues to Topics like you mentioned in #2 above. It's an optional piece of middleware that can be installed with Weblogic. It has all sorts of routing options for JMS and web services.
Here is a quick look:
http://www.orafmwschool.com/oracle-service-bus-routing-and-transformation/
http://www.slideshare.net/gschmutz/where-andwhentousetheoracleservicebusv2
We are using it for very much the same purpose that you're looking for.
Take a look at JMS routing using Apache CAMEL
<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
<!-- simple bridge from a topic to queue -->
<route>
<from uri="activemq:topic:topic.HelloWorld.incoming"> <to uri="activemq:queue:queue.HelloWorld">
</route>
</camelContext>

exact example for JMS Topic in HornetQ

I read the hornetQ documentation, confused a lot. Can someone give an exact example to create a JMS topic in hornetQ. I mean the xml configurations in hornetq-jms.xml and hornetq-configuration.xml. assume we have a topic named top and 2 subscribers named: sub1, sub2. what I get is that we should define two queues(one for each subscribers) and bind them to an address which is the topic name actually, but how the subscriber would know they should connect to which one?(They only know the topic name)
I think you are confused by the way HornetQ handles topics internaly in contrast to the way the JMS specification describes topics.
Let's start with the JMS specification. Here you have one topic, where n subscribers can listen to the messages, that will be published by a client. In JMS we talk only about the destination in singular, eg. we'll send a message to the topic, or the queue respectively.
HornetQ is a JMS Provider - a server that implements the JMS specification, so Java-clients can connect to it, and use the JMS-API. The JMS Provider might change, but the code should still work when using another JMS provider.
However, HornetQ does not distinguish internally the destinations (topic or queue), since it tries to be a generic messaging middleware. In HornetQ all topics or queues are implemented as "addresses" and "queues". When you use the HornetQ API (CoreAPI) instead of the JMS-API, you have to deal with such things. You should read the Address section in the HornetQ documentation:
In core, there is no concept of a Topic, Topic is a JMS only term.
Instead, in core, we just deal with addresses and queues.
For example, a JMS topic would be implemented by a single address to
which many queues are bound. Each queue represents a subscription of
the topic. A JMS Queue would be implemented as a single address to
which one queue is bound - that queue represents the JMS queue.
For an example how to use a topic with JMS via HornetQ, I stongly recommend the examples that come with HornetQ itself. After donwloading and extracting the hornetq archive, just go to the examples/jms/topic directory and see the readme.html for a brief overview how to implement and how to execute the example (mvn verify).

WMQ Pub/Sub Topic to Queue bridge

In other queue managers it is possible to setup a bridge between a queue to a topic so that publishers and subscribers does not need to know that they are using a topic:
Example in TIBCO EMS
create Bridge source=queue:QName
target=topic:TName
create Bridge
source=topic:TName target=queue:QName
How do I do this in WMQ?
See WebSphere MQ V7.0 Features and Enhancements page 47, it mentions the use of Alias queues and administrative subscriptions
WebSphere MQ V7.0 introduces an
extension to the alias queue object
that allows it to be resolved to the
new topic object. This is useful for
migrating point-to-point messaging
applications to the Publish/Subscribe
model. A traditional point-to-point
application that puts messages into
WebSphere MQ can operate as a
publisher without any code changes by
utilizing an alias queue that resolves
to a topic object. This is implemented
administratively by defining a topic
object that maps to an appropriate
topic string on which the messages are
to be published. The original local
queue is deleted and replaced by an
alias queue of the same name that
resolves to the topic object. Also
note that a point-to-point application
that gets messages from WebSphere MQ
can operate as a subscriber without
any code changes by defining an
administrative subscription to a
topic.
Example 9.3 on page 220 shows how to setup a administrative subscription from a Topic to a destination queue
DEFINE SUB(SUB.RETAIL.CAT) TOPICOBJ(MATT.RETAIL.CAT) DESTCLAS(MANAGED)
DEFINE SUB(SUB.MATTRETCAT) TOPICSTR(‘matt/retail/cat’) DESTCLAS(MANAGED)
DEFINE SUB(SUB.PROVCAT) TOPICSTR(‘matt/retail/cat’) DEST(SUB.PROVCAT.DESTQ)

ActiveMQ single consumer multiple producers

Can anybody point out a reference on how to implement
a single consumer multiple producer in activemq? Or could give a very simple implementation.
This will be very helpful.
Thanks
Matt Raible's AppFuse project is a good skeleton project which is implemented using different libraries. You can pick the one which uses Spring and introduce ActiveMQ as Bharati Raja has explained in his blog post jms with appfuse1x.
There is no special implementation required for this. This is the core business of MessageBrokers. The only thing you need to make sure of:
If you decide to give an ID to your producers, make sure they are different from each other.. You cannot have multiple producers with the same ID. Same goes for consumers.
If you need to guarantee that a message can be consumed by only one consumer, then this is the point-to-point communication model which can be implemented using a JMS Queue in ActiveMQ.
Many producers can send messages to the same queue. Only one active consumer will receive a message from the queue.

Resources