You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by rwolson <ri...@comcast.net> on 2012/06/12 19:31:08 UTC
Questions re: VirtualTopics
Good afternoon,
I’m attempting to use ActiveMQ 5.6.0 VirtualTopics for the first time.
Also, I’m somewhat a newbie to ActiveMQ and JMS.
I created a class based upon an shown in ActiveMQ in Action, page 285.
The code follows for reference:
public void sendAndConsumeVirtualTopic() throws JMSException {
String brokerURI = ActiveMQConnectionFactory.DEFAULT_BROKER_URL;
ConnectionFactory connectionFactory = new
ActiveMQConnectionFactory(brokerURI);
Connection consumerConnection = connectionFactory.createConnection();
consumerConnection.start();
Session consumerSessionA =
consumerConnection.createSession(false,Session.AUTO_ACKNOWLEDGE);
Queue consumerAQueue =
consumerSessionA.createQueue("Consumer.A.VirtualTopic.orders");
MessageConsumer consumerA =
consumerSessionA.createConsumer(consumerAQueue);
MessageListener listener = null;
consumerA.setMessageListener(listener);
//setup the sender
Connection senderConnection = connectionFactory.createConnection();
senderConnection.start();
Session senerSession = senderConnection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Topic ordersDestination =
senerSession.createTopic(ExamplePublishAndSubscribe.TOPIC1);
MessageProducer producer = senerSession.createProducer(ordersDestination);
String[] arry = {"Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot",
"Golf", "Hotel", "India", "Juliett", "Kilo", "Lima", "Mike", "November",
"Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor",
"Whiskey", "Xray", "Yankee", "Zulu"};
int index = 0;
while(index < arry.length) {
TextMessage message = senerSession.createTextMessage("Here is a message
[" + msgCount + "] " + arry[msgCount].toString() + " at: " + new Date());
producer.send(message);
index++;
}
consumerConnection.close();
bStopped = true;
} // end method
I’m successfully sending messages to Topics and the method creates a queue.
However, I don’t see any messages in the queue. Also, the code example
references a getMessageListener(), but since it’s not included within the
book’s source code, I suspect maybe I’m incorrectly initializing the
MessageListener. So, how do I setup the MessageListener?
I included the following entries within the activemq.xml and know they’re
read because I initially generated an error.
<destinationInterceptors>
<virtualDestinationInterceptor>
<virtualDestinations>
<virtualTopic name="orders"
prefix="VirtualTopic.*." />
</virtualDestinations>
</virtualDestinationInterceptor>
</destinationInterceptors>
Do I need to define the queue within the destinationInterceptors?
So, the questions just in case they’re hard to find:
- *how do I setup the MessageListener?*
- *Do I need to define the queue within the destinationInterceptors?*
Thanks,
Rich
--
View this message in context: http://activemq.2283324.n4.nabble.com/Questions-re-VirtualTopics-tp4653208.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
Re: Questions re: VirtualTopics
Posted by rwolson <ri...@comcast.net>.
Good morning,
Just a quick update. I resolved my problem based upon the example provided
by mr Tully. Yes, stupid user tricks in my case.
Rich
--
View this message in context: http://activemq.2283324.n4.nabble.com/Questions-re-VirtualTopics-tp4653208p4653435.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
Re: Questions re: VirtualTopics
Posted by rwolson <ri...@comcast.net>.
Great, I'll take a look at the link. Thank you, sir.
--
View this message in context: http://activemq.2283324.n4.nabble.com/Questions-re-VirtualTopics-tp4653208p4653246.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
Re: Questions re: VirtualTopics
Posted by Gary Tully <ga...@gmail.com>.
The unit tests are always a great starting point for working code:
have a peek at http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/VirtualTopicPubSubTest.java?view=markup
I think below you need to sent to a topic called: VirtualTopic.orders
On 12 June 2012 18:31, rwolson <ri...@comcast.net> wrote:
> Good afternoon,
>
> I’m attempting to use ActiveMQ 5.6.0 VirtualTopics for the first time.
> Also, I’m somewhat a newbie to ActiveMQ and JMS.
>
> I created a class based upon an shown in ActiveMQ in Action, page 285.
> The code follows for reference:
> public void sendAndConsumeVirtualTopic() throws JMSException {
> String brokerURI = ActiveMQConnectionFactory.DEFAULT_BROKER_URL;
>
> ConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory(brokerURI);
> Connection consumerConnection = connectionFactory.createConnection();
> consumerConnection.start();
>
> Session consumerSessionA =
> consumerConnection.createSession(false,Session.AUTO_ACKNOWLEDGE);
> Queue consumerAQueue =
> consumerSessionA.createQueue("Consumer.A.VirtualTopic.orders");
> MessageConsumer consumerA =
> consumerSessionA.createConsumer(consumerAQueue);
> MessageListener listener = null;
> consumerA.setMessageListener(listener);
>
> //setup the sender
> Connection senderConnection = connectionFactory.createConnection();
> senderConnection.start();
> Session senerSession = senderConnection.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
> Topic ordersDestination =
> senerSession.createTopic(ExamplePublishAndSubscribe.TOPIC1);
> MessageProducer producer = senerSession.createProducer(ordersDestination);
>
> String[] arry = {"Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot",
> "Golf", "Hotel", "India", "Juliett", "Kilo", "Lima", "Mike", "November",
> "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor",
> "Whiskey", "Xray", "Yankee", "Zulu"};
> int index = 0;
> while(index < arry.length) {
> TextMessage message = senerSession.createTextMessage("Here is a message
> [" + msgCount + "] " + arry[msgCount].toString() + " at: " + new Date());
> producer.send(message);
> index++;
> }
>
> consumerConnection.close();
> bStopped = true;
> } // end method
>
> I’m successfully sending messages to Topics and the method creates a queue.
> However, I don’t see any messages in the queue. Also, the code example
> references a getMessageListener(), but since it’s not included within the
> book’s source code, I suspect maybe I’m incorrectly initializing the
> MessageListener. So, how do I setup the MessageListener?
>
> I included the following entries within the activemq.xml and know they’re
> read because I initially generated an error.
> <destinationInterceptors>
> <virtualDestinationInterceptor>
> <virtualDestinations>
>
>
> <virtualTopic name="orders"
> prefix="VirtualTopic.*." />
> </virtualDestinations>
> </virtualDestinationInterceptor>
> </destinationInterceptors>
>
> Do I need to define the queue within the destinationInterceptors?
>
> So, the questions just in case they’re hard to find:
> - *how do I setup the MessageListener?*
> - *Do I need to define the queue within the destinationInterceptors?*
>
> Thanks,
> Rich
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Questions-re-VirtualTopics-tp4653208.html
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
--
http://fusesource.com
http://blog.garytully.com