• ActiveMQ(5.10.0)


    1. Place the jndi.properties file on the classpath.

    java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
     
    # use the following property to configure the default connector
    java.naming.provider.url = vm://localhost
     
    # use the following property to specify the JNDI name the connection factory
    # should appear as. 
    connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry
     
    # register some queues in JNDI using the form
    # queue.[jndiName] = [physicalName]
    queue.MyQueue = example.MyQueue
     
     
    # register some topics in JNDI using the form
    # topic.[jndiName] = [physicalName]
    topic.MyTopic = example.MyTopic

    2. Sample code

    // create a new intial context, which loads from jndi.properties file
    javax.naming.Context ctx = new javax.naming.InitialContext();
    // lookup the connection factory
    javax.jms.ConnectionFactory factory = (javax.jms.ConnectionFactory) ctx.lookup("connectionFactory");
    // create a new Connection for messaging
    javax.jms.Connection conn = factory.createConnection();
    // lookup an existing queue
    javax.jms.Destination destination = (javax.jms.Destination) ctx.lookup("MyQueue");
    // create a new Session for the client
    javax.jms.Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // create a new consumer to receive messages
    javax.jms.MessageConsumer consumer = session.createConsumer(destination);
  • 相关阅读:
    BZOJ2741:[FOTILE模拟赛]L
    BZOJ3996:[TJOI2015]线性代数
    BZOJ3876:[AHOI2014]支线剧情
    BZOJ1861:[ZJOI2006]Book书架
    BZOJ3190:[JLOI2013]赛车
    HDU-1540 Tunnel Warfare 【线段树+单点修改+区间更新】
    HDU-1846 Brave Game 【巴什博弈】
    HDU-1421 搬寝室 【DP】
    HDU-4734 F(x) 【数位DP】
    AHU-412 Bessie Come Home 【Dijkstra】
  • 原文地址:https://www.cnblogs.com/huey/p/4748767.html
Copyright © 2020-2023  润新知