pom.xml

<!-- mq 依赖 -->
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.6.2</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
<version>1.6.0.RELEASE</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>1.6.0.RELEASE</version>
</dependency>

配置连接池

spring-bean.xml

<bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<!-- <property name="addresses" value="192.168.1.237,192.168.1.239,192.1.168.240" /> -->
<property name="addresses" value="192.168.1.33" />
<property name="username" value="mq"/>
<property name="password" value="mq"/>
<property name="channelCacheSize" value="50"/>
<property name="publisherConfirms" value="true" />
</bean>

实现代码

@Resource
private ConnectionFactory connectionFactory; public void createMq(String msgQueue, String exchage) throws Exception {
// set up the queue, exchange, binding on the broker
RabbitAdmin admin = new RabbitAdmin(connectionFactory);
Queue queue = new Queue(msgQueue);
//queue
admin.declareQueue(queue);
//exchange
DirectExchange exchange = new DirectExchange(exchage);
admin.declareExchange(exchange);
//binding
admin.declareBinding(
BindingBuilder.bind(queue).to(exchange).with("")); }

spring-amqp 动态创建queue、exchange、binding的更多相关文章

  1. spring动态创建数据源

    在最近的项目业务中,需要在程序的运行过程中,添加新的数据库添链接进来,然后从新数据库链接中读取数据. 网上查阅了资料,发现spring为多数据源提供了一个抽象类AbstractRoutingDataS ...

  2. 使用Spring AMQP开发消费者应用

    前一篇中我们介绍了使用RabbitMQ Java Client访问RabbitMQ的方法.但是使用这种方式访问RabbitMQ,开发者在程序中需要自己管理Connection,Channel对象,Co ...

  3. spring 动态创建数据源

    项目需求如下,公司对外提供服务,公司本身有个主库,另外公司会为每个新客户创建一个数据库,客户的数据库地址,用户名,密码,都保存在主数据库中.由于不断有新的客户加入,所以要求,项目根据主数据库中的信息, ...

  4. Spring Boot:实现MyBatis动态创建表

    综合概述 在有些应用场景中,我们会有需要动态创建和操作表的需求.比如因为单表数据存储量太大而采取分表存储的情况,又或者是按日期生成日志表存储系统日志等等.这个时候就需要我们动态的生成和操作数据库表了. ...

  5. Spring 动态创建并切换数据源

    公司要求后端项目可以进行动态创建并切换数据源,看了网上很多例子大多数使用的都是Spring内置的AbstractRoutingDataSource进行的,使用此方法不是不行但是有诸多缺陷,比如切换时需 ...

  6. 消息中间件——RabbitMQ(九)RabbitMQ整合Spring AMQP实战!(全)

    前言 1. AMQP 核心组件 RabbitAdmin SpringAMQP声明 RabbitTemplate SimpleMessageListenerContainer MessageListen ...

  7. RabbitMQ与Spring的框架整合之Spring AMQP实战

    1.SpringAMQP用户管理组件RabbitAdmin. RabbitAdmin类可以很好的操作RabbitMQ,在Spring中直接进行注入即可.注意,autoStartup必须设置为true, ...

  8. spring amqp rabbitmq fanout配置

    基于spring amqp rabbitmq fanout配置如下: 发布端 <rabbit:connection-factory id="rabbitConnectionFactor ...

  9. Spring AMQP + Rabbit 配置多数据源消息队列

    一般在稍微大一点的项目中,需要配置多个数据库数据源,最简单的方式是用 Spring 来实现,只需要继承 AbstractRoutingDataSource 类,实现 determineCurrentL ...

随机推荐

  1. 浅谈C语言中结构体的初始化

    转自:http://www.jb51.net/article/37246.htm <代码大全>建议在变量定义的时候进行初始化,但是很多人,特别是新人对结构体或者结构体数组定义是一般不会初始 ...

  2. [译]:Orchard入门——使用标签管理内容

    原文链接:Organizing Content Using Tags 在Orchard中,内容项可以使用标签来分类,同时,通过格式为 ~/tags/tag-name 的url可以直接查看包含对应标签关 ...

  3. 坐标系统与投影变换及在ARCGIS中的应用

      首先提几个问题:是否有遇到坐标转换的问题?又是否有遇到投影转换的问题?坐标转换与投影转换有什么区别?下面看几个概念:1.地球椭球体( Ellipsoid,Spheroid)2.大地基准面( Geo ...

  4. 用 TWebBrowser 查找网页上的按钮,编辑框,

    Form1.wb1.Navigate(Aurl); <table> <tr> <td style="text-align:right;">< ...

  5. linux下 html转pdf

    其实很简单的, 在当前文件夹中打开终端, 只需要一个命令就好 wkhtmltopdf test.html test.pdf 这样一个test.html的文件就转为test.pdf 的pdf文件啦!

  6. 未能加载文件或程序集“System.Data.SQLite”或它的一个依赖。试图加载格式不正确的程序

    Go to the IIS7 Application Pool -> advanced settings and set the 32-bit application to true.

  7. BZOJ4712 : 洪水

    首先不难列出DP方程: $dp[x]=\min(w[x],h[x])$ $h[x]=\sum dp[son]$ 当$w[x]$增加时,显然$dp[x]$不会减少,那么我们求出$dp[x]$的增量$de ...

  8. WPF 四种样式

    1.内联样式<TextBlock FontSize="20" Foreground="Blue">好啊</TextBlock> 2.页面 ...

  9. bigint数据类型

    尽管int依然是SQL Server 2000中最主要的整数数据类型,但是SQL Server 2000还是新增加了整数数据类型bigint,它应用于整数超过int数据范围的场合. int数据类型所表 ...

  10. Hint when use HTTPAgilityPack

    1- Read the usage policy of the website. I know this is the third time I mention that, but that tell ...