开发者

Apache ActiveMQ Connect to a topic non-dynamically

I've set up ActiveMQ and I can create/connect to a topic using "dynamicTopics/MyTopic". This works great:

    Properties env = new Properties( );
    env.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    env.setProperty(Context.PROVIDER_URL,"tcp://myhostname:xxxxx");
    javax.naming.Context ctx = new InitialContext(env);

    InitialContext jndi = new InitialContext(env);

    // Look up a JMS connection factory
    TopicConnectionFactory conFactory = (TopicConnectionFactory)jndi.lookup("TopicConnectionFactory");

    // Create a JMS connection
    TopicConnection connection = conFactory.createTopicConnection(username,password);

    Topic chatTopic = (Topic)jndi.lookup("dynamicTopics/MyTopic");

I would like to connect to a topic already exists without dynamical开发者_如何学JAVAly creating the topic if it doesn't exist, how can I do so?

Cheers,

Pete


While you don't need to create destinations manually with AMQ you always have that option. Basically you can alter the security settings to allow only an admin to create destinations. See the AMQ FAQ for this:

http://activemq.apache.org/how-do-i-create-new-destinations.html

Regards

Tim www.fusesource.com


What you are actually doing is just connecting to topic. ActiveMQ is so nice that it creates topic for you if it did not exist before.

So, to connect to already existing topic just do the same that you are already doing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜