springmvc整合rabbitmq实现消息发送消息确认
首先springmvc创建项目的教程,这里就不多说了,现在重点看一下springmvc整合rabbitmq的教程。
首先引入jar包我这里用的是2.1.6版本
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
在配置文件中配上rabbitmq的配置
# rabbit ip
rabbit.host=127.0.0.1
# rabbit 端口
rabbit.port=5672
# rabbit 用户名
rabbit.username=admin
# rabbit 密码
rabbit.password=123456
使用xml配置消息发送者
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
<!-- 配置连接工厂 -->
<rabbit:connection-factory id="connectionFactory"
host="${rabbit.host}" port="${rabbit.port}"
username="${rabbit.username}" password="${rabbit.password}"
publisher-confirms="true" publisher-returns="true" /