返回顶部

收藏

使用JAVA实现RabbitMQ的发送告警

更多

基于rabbitmq实战4.2章节发送即忘模型,书上是使用PiPa库完成,这里使用java实现``` java package com.rayootech.rabbitmq.demo.inaction.alertwarning;

import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; import com.rabbitmq.client.ConnectionFactory;

public class AlertWarningProducer { private static final String EXCHANGE_NAME = "alerts"; private static final String ROUTING_KEY = "critical.alert"; public static void main(String[] argv) { Connection connection = null; Channel channel = null; try { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("rabbitmq128"); factory.setUsername("admin"); factory.setPassword("admin"); factory.setPort(5672);

        connection = factory.newConnection();
        channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, "topic",true);

        String message = "critical content!!!";

        channel.basicPublish(EXCHANGE_NAME, ROUTING_KEY, null, message.getBytes());
        System.out.println(" [x] Sent '" + ROUTING_KEY + "':'" + message + "'");

    }
    catch  (Exception e) {
        e.printStackTrace();
    }
    finally {
        if (connection != null) {
            try {
                connection.close();
            }
            catch (Exception ignore) {}
        }
    }
}

}

``` java None

标签:java

收藏

0人收藏

支持

0

反对

0

相关聚客文章
  1. 博主 发表 2014-06-24 00:00:00 Java Microbenchmarking Harness(jmh)
  2. 博主 发表 2014-06-23 00:00:00 Java Object Layout(jol)
  3. 博主 发表 2014-06-23 00:00:00 Java Concurrency Stress(jcstress)
  4. 博主 发表 2014-05-17 00:00:00 Java Performance:The Definitive Guide Chapter 4
  5. 博主 发表 2014-05-15 00:00:00 Java Performance:The Definitive Guide Chapter 3
  6. 博主 发表 2014-04-27 00:00:00 Java Performance:The Definitive Guide Chapter 1 2
  7. 博主 发表 2014-04-22 00:00:00 java core dump analysis
  8. 博主 发表 2014-04-16 00:00:00 java cpu monitor
  9. 博主 发表 2014-03-11 00:00:00 Java Mission Control
  10. TiuVe2 发表 2017-10-01 12:18:44 Java 技术之垃圾回收机制
  11. TiuVe2 发表 2017-10-01 12:27:10 Java 守护线程概述
  12. TiuVe2 发表 2017-10-06 15:29:51 Java 里如何实现线程间通信

发表评论