91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

activemq 編程式客戶端

發布時間:2020-07-30 18:39:37 來源:網絡 閱讀:455 作者:乾坤刀 欄目:軟件技術

dependency

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-client</artifactId>
    <version>${activemq.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-spring</artifactId>
    <version>${activemq.version}</version>
</dependency>

ActivemqProducerTest

public class ActivemqProducerTest {

    private static final String producer_broker_url = "failover:(tcp://localhost:61617,tcp://localhost:61618,tcp://localhost:61619)";
    private static final String username = "admin";
    private static final String password = "admin123";
    private static final String destination_queue = "queue.test01";
    private static final String destination_topic = "topic.test01";

    public static void main(String[] args) throws JMSException {
        produceInQueue();
        produceInTopic();
    }

    private static void produceInQueue() throws JMSException {
        // activeMQ connection factory
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
        activeMQConnectionFactory.setBrokerURL(producer_broker_url);
        activeMQConnectionFactory.setUserName(username);
        activeMQConnectionFactory.setPassword(password);

        Connection connection = activeMQConnectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        ActiveMQQueue dest = new ActiveMQQueue(destination_queue);

        TextMessage textMessage = session.createTextMessage();
        textMessage.setText("this is a test...");

        MessageProducer producer = session.createProducer(dest);
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        producer.send(textMessage);

        connection.close();
    }

    private static void produceInTopic() throws JMSException {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
        activeMQConnectionFactory.setBrokerURL(producer_broker_url);
        activeMQConnectionFactory.setUserName(username);
        activeMQConnectionFactory.setPassword(password);

        Connection connection = activeMQConnectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        ActiveMQTopic dest = new ActiveMQTopic(destination_topic);

        MapMessage mapMessage = session.createMapMessage();
        mapMessage.setString("key01","val01");
        mapMessage.setInt("key02", 2);

        MessageProducer producer = session.createProducer(dest);
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        producer.send(mapMessage);

        connection.close();
    }
}
ActivemqCustomerTest
public class ActivemqCustomerTest {

    private static final String producer_broker_url = "failover:(tcp://localhost:61617,tcp://localhost:61618,tcp://localhost:61619)";
    private static final String username = "admin";
    private static final String password = "admin123";
    private static final String destination_queue = "queue.test01";
    private static final String destination_topic = "topic.test01";

    public static void main(String[] args) throws JMSException {
        consumeTopic();
        consumeTopic();
        consumeQueue();
    }

    private static void consumeTopic() throws JMSException {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
        activeMQConnectionFactory.setBrokerURL(producer_broker_url);
        activeMQConnectionFactory.setUserName(username);
        activeMQConnectionFactory.setPassword(password);

        Connection connection = activeMQConnectionFactory.createConnection();
        connection.setExceptionListener(new ExceptionListener(){
            @Override
            public void onException(JMSException exception) {
                System.out.println("JMSException:"+exception.getMessage());
            }
        });
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        ActiveMQTopic dest = new ActiveMQTopic(destination_topic);

        MessageConsumer consumer = session.createConsumer(dest);
        consumer.setMessageListener(new MessageListener(){
            @Override
            public void onMessage(Message message) {
                try {
                    if (message instanceof TextMessage){
                        System.out.println("message = [" + ((TextMessage) message).getText() + "]");
                    }
                    if (message instanceof MapMessage){
                        MapMessage mapMessage = (MapMessage) message;
                        System.out.println("key01 = [" + mapMessage.getString("key01") + "]");
                        System.out.println("key02 = [" + mapMessage.getInt("key02") + "]");
                    }
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            }
        });

        //   connection.close();
    }


    private static void consumeQueue() throws JMSException {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
        activeMQConnectionFactory.setBrokerURL(producer_broker_url);
        activeMQConnectionFactory.setUserName(username);
        activeMQConnectionFactory.setPassword(password);

        Connection connection = activeMQConnectionFactory.createConnection();
        connection.setExceptionListener(new ExceptionListener(){
            @Override
            public void onException(JMSException exception) {
                System.out.println("JMSException:"+exception.getMessage());
            }
        });
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        ActiveMQQueue dest = new ActiveMQQueue(destination_queue);

        MessageConsumer consumer = session.createConsumer(dest);
        consumer.setMessageListener(new MessageListener(){
            @Override
            public void onMessage(Message message) {
                try {
                    if (message instanceof TextMessage){
                        System.out.println("message = [" + ((TextMessage) message).getText() + "]");
                    }
                    if (message instanceof MapMessage){
                        MapMessage mapMessage = (MapMessage) message;
                        System.out.println("key01 = [" + mapMessage.getString("key01") + "]");
                        System.out.println("key02 = [" + mapMessage.getInt("key02") + "]");
                    }
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            }
        });

        //   connection.close();
    }
}


集群配置地址:https://blog.51cto.com/881206524/2129863







向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

通州市| 五华县| 雷山县| 东宁县| 海安县| 师宗县| 舞阳县| 屏东市| 平远县| 凉山| 沙坪坝区| 江都市| 安西县| 吴江市| 泰宁县| 阿坝| 郎溪县| 阳江市| 镇原县| 吉木乃县| 信丰县| 德兴市| 芜湖市| 桃江县| 巫山县| 个旧市| 得荣县| 贵港市| 台州市| 宝清县| 天津市| 神木县| 罗平县| 林甸县| 呼图壁县| 文山县| 福鼎市| 微博| 康定县| 潞城市| 大关县|