zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    (二)全局属性
    (十二)this关键字
    (十一)构造方法的重载和成员方法的重载
    (十)foreac遍历、break和countinue以及标签和switch循环
    java集合
    关于java赋值操作的原子性问题
    spring list map set
    apache benchmark
    为什么java web项目中要使用spring
    spring IOC
  • 原文地址:https://www.cnblogs.com/huey/p/4748767.html
Copyright © 2011-2022 走看看