Apologies in advance if this shows up twice, but I seem to have had problems sending from my work account...

---

Hello.

I have been playing around with the Hello.java example that came with qpid-java-client-0.24.tar.gz. I have installed the qpidd package (the broker) on a Ubuntu 12.04 LTS platform along with the qpid-tools package
(from the Ubuntu Software Centre).

I am looking to try and integrate the Qpid broker with JMS-based clients. I am brand new to all of the concepts and my understanding is possibly being confused by the differences in terminology between JMS and Qpid elements. I would greatly appreciate if you can indulge a few questions arising from my initial foray...

By modifying the code to use the pub/sub API, I have arrived at this source (Hello2.java):

--------
package org.apache.qpid.example;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;

public class Hello2
{
   public Hello2()
   {
  }
   public static void main(String[] args)
   {
       Hello2 hello2 = new Hello2();
       hello2.runTest();
   }
   private void runTest()
   {
       try {
           Properties properties = new Properties();
           
properties.load(this.getClass().getResourceAsStream("hello2.properties"));
           Context context = new InitialContext(properties);
TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) context.lookup("qpidConnectionfactory"); TopicConnection topicConnection = topicConnectionFactory.createTopicConnection();
           topicConnection.start();
TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
           Topic topic = (Topic) context.lookup("topicExchange");
           System.out.println(topic.getTopicName());

TopicPublisher topicPublisher = topicSession.createPublisher(topic); TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic); TextMessage message = topicSession.createTextMessage("Hello world!");
           topicPublisher.publish(message);
           message = (TextMessage)topicSubscriber.receive();
           System.out.println(message.getText());
           topicConnection.close();
           context.close();
       }
       catch (Exception exp)
       {
           exp.printStackTrace();
       }
   }
}
--------

Now, hello2.properties looks like this:
--------
java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextFactory
# register some connection factories
# connectionfactory.[jndiname] = [ConnectionURL]
connectionfactory.qpidConnectionfactory = amqp://guest:guest@clientid/?brokerlist='tcp://localhost:5672'
# Register an AMQP destination in JNDI
# destination.[jniName] = [Address Format]
destination.topicExchange = news-service2
#topic.topicExchange = news-service2
--------

Before running the program, I adminstratively create the topic exchange via qpid-config:
% qpid-config add exchange topic news-service2

Now... "AS-IS", the above code/properties combination "works" - i.e. when I compile and run Hello2.jar, I see this output:
--------
null
Hello world!
--------

If I use the command-line "qpid-stat -e", I do indeed see msgIn and msgOut counters incrementing for the "news-service2"
topic exchange.
What I don't understand (my first question) here is why the "topic.getTopicName()" call is returning "null" in this instance?

When I substitute "topic.topicExchange" for "destination.topicExchange" in the hello2.properties file, I get this output:
--------
news-service2
Hello world!
--------

Here, "topic.getTopicName()" actually returns the expected string "news-service2". However, in this case "qpid-stat-e" shows that the corresponding topic exchange "news-service2" has NOT changed its msgIn/msgOut counters, BUT the counts for amq.topic have changed instead. My second question therefore is why have these
messages ended up in amq.topic?

A final question (more of a related query). If I use the default (original) example code Hello.java, but in hello.properties substitute "destination.topicExchange = amq.topic" for "queue.topicExchange = some_queue_name", I note that even if "some_queue_name" did not exist in the broker prior to running Hello, then it is created. This behaviour doesn't seem to work
for "topic.topicExchange" so I was wondering why the discrepancy.

Thanks for indulging these newbie questions!

Mark.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org

Reply via email to