commons-rabbitmq
Used in:
components
- OverviewOverview
- VersionsVersions
- DependentsDependents
- DependenciesDependencies
<dependency> <groupId>com.github.luues</groupId> <artifactId>commons-rabbitmq</artifactId> <version>1.2.3.RELEASE</version> </dependency>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <name>commons-rabbitmq</name> <groupId>com.github.luues</groupId> <artifactId>commons-rabbitmq</artifactId> <packaging>jar</packaging> <version>1.2.3.RELEASE</version> <url>https://github.com/luues/spring-luues/tree/master/commons-rabbitmq</url> <description>A Simple Rabbitmq Package</description> <licenses> <license> <name>The Apache Software License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> </license> </licenses> <developers> <developer> <name>wuguo</name> <email>wuguo@luues.github.com</email> </developer> </developers> <scm> <connection>scm:git:https://github.com/luues/spring-luues.git</connection> <developerConnection>scm:git:https://github.com/luues/spring-luues.git</developerConnection> <url>https://github.com/luues/spring-luues/tree/master/commons-rabbitmq</url> </scm> <distributionManagement> <snapshotRepository> <id>oss</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> </snapshotRepository> <repository> <id>oss</id> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> </repository> </distributionManagement> <!-- 发送: @Autowired private com.luues.rabbitmq.producer.service.RabbitTemplate rabbitTemplate; rabbitTemplate.send(QueueConstant.QUEUE_NAME, "我准备下单了"); rabbitTemplate.send(QueueConstant.TOPIC_EXCHANGE_NAME, QueueConstant.TOPIC_EXCHANGE_NAME + ".order", "我下单了"); rabbitTemplate.send(QueueConstant.TOPIC_EXCHANGE_NAME, QueueConstant.TOPIC_EXCHANGE_NAME + ".pay", "我付款了"); rabbitTemplate.send(QueueConstant.TOPIC_EXCHANGE_NAME, QueueConstant.TOPIC_EXCHANGE_NAME + ".#all", "日记记录(下单,付款)"); rabbitTemplate.send(QueueConstant.FANOUT_EXCHANGE_NAME, "", "系统通知了所有人"); 消费: @RabbitListener( bindings = @QueueBinding( value = @Queue(), //注意这里不要定义队列名称,系统会随机产生 exchange = @Exchange(value = QueueConstant.FANOUT_EXCHANGE_NAME, type = ExchangeTypes.FANOUT) ) ) public void dealBody1(String body) { LogUtil.error("广播:{}", body); } @RabbitListener( bindings = @QueueBinding( value = @Queue(QueueConstant.TOPIC_EXCHANGE_NAME + ".pay"), exchange = @Exchange(value = QueueConstant.TOPIC_EXCHANGE_NAME, type = ExchangeTypes.TOPIC), key = QueueConstant.TOPIC_EXCHANGE_NAME + ".pay" ) ) public void dealBody2(String body) { LogUtil.error("付款:{}", body); } @RabbitListener( bindings = @QueueBinding( value = @Queue(QueueConstant.TOPIC_EXCHANGE_NAME + ".order"), exchange = @Exchange(value = QueueConstant.TOPIC_EXCHANGE_NAME, type = ExchangeTypes.TOPIC), key = QueueConstant.TOPIC_EXCHANGE_NAME + ".order" ) ) public void dealBody2_(String body) { LogUtil.error("订单:{}", body); } @RabbitListener( bindings = @QueueBinding( value = @Queue(QueueConstant.TOPIC_EXCHANGE_NAME + ".#all"), exchange = @Exchange(value = QueueConstant.TOPIC_EXCHANGE_NAME, type = ExchangeTypes.TOPIC), key = QueueConstant.TOPIC_EXCHANGE_NAME + ".#" ) ) public void dealBody2__(String body) { LogUtil.error("系统通知接收所有rabbitmq_qty_topicExchange开头的message:{}", body); } @RabbitListener( queuesToDeclare = @Queue(QueueConstant.QUEUE_NAME), containerFactory = QueueConstant.MANUAL ) public void dealBody3(@Payload String message, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) throws IOException { LogUtil.error("普通消息:{}", message); channel.basicAck(deliveryTag, false); //确认消息消费成功 //channel.basicNack(deliveryTag, false, true); 重新消费,直到成功 //channel.basicNack(deliveryTag, false, false); 消费失败,无需重新消费 } 延迟消息 @RabbitListener( bindings = @QueueBinding( value = @Queue(value = "send_del_msg", durable = "true"), exchange = @Exchange(value = "del_exchange", type = ExchangeTypes.DIRECT, delayed = Exchange.TRUE), arguments = @Argument(name = "x-delayed-type", value = "direct"), key = "send_del_msg" ), containerFactory = QueueConstant.MANUAL ) --> <parent> <groupId>com.github.luues</groupId> <artifactId>boot-pom</artifactId> <version>1.2.1.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency> </dependencies> <build> <finalName>commons-rabbitmq</finalName> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <!-- Source --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <!-- Javadoc --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.9.1</version> <configuration> <show>private</show> <nohelp>true</nohelp> <charset>UTF-8</charset> <encoding>UTF-8</encoding> <docencoding>UTF-8</docencoding> <additionalparam>-Xdoclint:none </additionalparam> <!-- TODO 临时解决不规范的javadoc生成报错,后面要规范化后把这行去掉 --> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!-- GPG --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId> <version>1.5</version> <executions> <execution> <phase>verify</phase> <goals> <goal>sign</goal> </goals> </execution> </executions> </plugin> </plugins> </pluginManagement> <resources> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> <excludes> <exclude>single-application.properties</exclude> <exclude>cluster-application.properties</exclude> </excludes> </resource> </resources> </build> </project>