找传奇、传世资源到传世资源站!
Java 正文

rabbitmq_实例源码下载_

  • 资源分类:Java
  • 发 布 人:房东的猫
  • 文件大小:408945
  • 文件格式:.rar
  • 浏览次数:17
  • 下载次数: 0
  • 发布时间:9月20日

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

/**
 * TODO
 * 
 */
package cn.itcast.topic;

/**
 * @author hushuang
 *
 */
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;

public class TopicSend {

	private static final String EXCHANGE_NAME = "topic_logs";

	public static void main(String[] argv) {
		Connection connection = null;
		Channel channel = null;
		try {
			ConnectionFactory factory = new ConnectionFactory();
			factory.setHost("localhost");

			connection = factory.newConnection();
			channel = connection.createChannel();
//			声明一个匹配模式的交换器
			channel.exchangeDeclare(EXCHANGE_NAME, "topic");

			// 待发送的消息
			String[] routingKeys = new String[]{"quick.orange.rabbit", 
												"lazy.orange.elephant", 
												"quick.orange.fox", 
												"lazy.brown.fox", 
												"quick.brown.fox", 
												"quick.orange.male.rabbit", 
												"lazy.orange.male.rabbit"};
//			发送消息
	    for(String severity :routingKeys){
	    	String message = "From " severity " routingKey' s message!";
	    	channel.basicPublish(EXCHANGE_NAME, severity, null, message.getBytes());
	    	System.out.println("TopicSend [x] Sent '"  severity  "':'"  message  "'");
	    }
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (connection != null) {
				try {
					connection.close();
				} catch (Exception ignore) {
				}
			}
		}
	}
}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复