软件开发教程 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试
游戏开发 网络协议 系统运维 HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程
C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
 
   -> 大数据 -> ssh配置多地址rabbitmq -> 正文阅读

[大数据]ssh配置多地址rabbitmq

1.属性文件配置rabbitmq连接信息
test.mq.host=xxx.xxx.xxx.xxx
test.mq.username=guest
test.mq.password=guest
test.mq.port=5672
test.mq.virtualhost=/

test.mq2.host=127.0.0.1
test.mq2.username=guest
test.mq2.password=guest
test.mq.port=5672
test.mq.virtualhost=/

2.分别在两个连接地址下创建ttt_queue和test_queue

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:int="http://www.springframework.org/schema/integration"
	xmlns:int-http="http://www.springframework.org/schema/integration/http"
	xmlns:int-xml="http://www.springframework.org/schema/integration/xml"
	xmlns:rabbit="http://www.springframework.org/schema/rabbit"
	xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
	xmlns:int-stream="http://www.springframework.org/schema/integration/stream" 
	xsi:schemaLocation="  
		     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 
		     http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.3.xsd
             http://www.springframework.org/schema/integration/amqp http://www.springframework.org/schema/integration/amqp/spring-integration-amqp-4.3.xsd 
			 http://www.springframework.org/schema/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd 	 
			 http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd 
			 http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd 
             http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.7.xsd">

	<!-- A reference to the org.springframework.amqp.rabbit.connection.ConnectionFactory -->
	<rabbit:connection-factory id="connectionFactory"
		host="${${switch}.mq.host}" username="${${switch}.mq.username}" password="${${switch}.mq.password}" port="${${switch}.mq.port}" virtual-host="${${switch}.mq.virtualhost}" 
		cache-mode="CONNECTION" connection-cache-size="24"/>
	

	<rabbit:admin connection-factory="connectionFactory"/>
	
	<!-- 消息对象json转换类 -->
    <bean id="jsonMessageConverter" class="org.springframework.amqp.support.converter.Jackson2JsonMessageConverter" />
    
	<!-- Creates a org.springframework.amqp.rabbit.core.RabbitTemplate for access to the broker -->
	<rabbit:template id="rabbitTemplate" connection-factory="connectionFactory" message-converter="jsonMessageConverter"/>
	
	<rabbit:queue id="ttt_queue" name="ttt_queue" durable="true" auto-delete="false" exclusive="false" auto-declare="true"/>
	<rabbit:direct-exchange id="ttt_exchange" name="ttt_exchange" durable="true">
		<rabbit:bindings>
			<rabbit:binding queue="ttt_queue" />
		</rabbit:bindings>
	</rabbit:direct-exchange>
	
	<rabbit:listener-container connection-factory="connectionFactory" acknowledge="none" message-converter="jsonMessageConverter">
		<rabbit:listener queues="ttt_queue" ref="registrationPlanService" method="hehe" />
	</rabbit:listener-container>

<!-- ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ --> 
	<!--配置connection-factory,指定连接rabbit server参数 -->
    <rabbit:connection-factory id="connectionFactory2"
                               username="${${switch}.mq2.username}" password="${${switch}.mq2.password}" host="${${switch}.mq2.host}" port="5672"/>
    <!--通过指定下面的admin信息,当前producer中的exchange和queue会在rabbitmq服务器上自动生成 -->
    <rabbit:admin connection-factory="connectionFactory2"/>
    <!--定义rabbit template用于数据的接收和发送 -->
    <rabbit:template id="rabbitTemplate2" connection-factory="connectionFactory2"
                     message-converter="jsonMessageConverter"/>
 
	<rabbit:queue id="test_queue" name="test_queue" durable="true" auto-delete="false" exclusive="false" auto-declare="true"/>
	<rabbit:fanout-exchange id="test_exchange" name="test_exchange" durable="true" auto-delete="false" auto-declare="true">
	    <rabbit:bindings>
	        <rabbit:binding queue="test_queue" />
	    </rabbit:bindings>
	</rabbit:fanout-exchange>
	
	<rabbit:listener-container connection-factory="connectionFactory2" acknowledge="none" auto-declare="true" message-converter="jsonMessageConverter" concurrency="2">
		<rabbit:listener queues="test_queue" ref="registrationPlanService" method="haha"/>
	</rabbit:listener-container>
	<!-- ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ --> 

</beans>

3.测试

@Resource(name="rabbitTemplate")
private RabbitTemplate rabbitTemplate;

@Resource(name="rabbitTemplate2")
private RabbitTemplate rabbitTemplate2;

/***
 * <p>Title: xixi</p>  
 * <p>Description: 生产者</p>  
 * @param mqMap
 */
public void xixi(Map<String, Object> mqMap) {
	try {
		rabbitTemplate2.convertAndSend("test_exchange", null, mqMap);
		rabbitTemplate.convertAndSend("ttt_exchange", null, mqMap);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
/***
 * <p>Title: haha</p>  
 * <p>Description: 消费者(rabbitTemplate2)</p>  
 * @param mqMap
 */
public void haha(Map<String, Object> mqMap) {
	try {
		String success = mqMap.get("success").toString();
		String info = mqMap.get("info").toString();
		logger.info("rabbitTemplate2 mq test_exchange 消费成功, success={}, info={}", success, info);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
/***
 * <p>Title: hehe</p>  
 * <p>Description: 消费者(rabbitTemplate)</p>  
 * @param mqMap
 */
public void hehe(Map<String, Object> mqMap) {
	try {
		String success = mqMap.get("success").toString();
		String info = mqMap.get("info").toString();
		logger.info("rabbitTemplate mq ttt_exchange 消费成功, success={}, info={}", success, info);
	} catch (Exception e) {
		e.printStackTrace();
	}
}

  大数据 最新文章
Zookeeper做配置中心
kafka安装和学习使用
spring-kafka消费者源码分析
实现flink自定义幂等写入ClickHouse,并封装
Flink CDC 2.0 设计方案
hadoop如何关闭namenode和datanode
Kafka基本命令
Flink on Zeppelin 流计算处理最佳实践
(尚硅谷)springData 集成 Elasticsearch
大数据hadoop hdfs 读写流程
上一篇文章      下一篇文章      查看所有文章
加:2021-07-17 11:59:21  更:2021-07-17 12:03:35 
 
360图书馆 购物 三丰科技 阅读网 日历 万年历 2021年7日历 -2021/7/27 2:58:21-
图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  软件开发教程