提交 6650f6c7 编写于 作者: 武汉红喜's avatar 武汉红喜

optimise

上级 f4943de8
...@@ -223,7 +223,9 @@ ...@@ -223,7 +223,9 @@
<scm> <scm>
<url>https://github.com/javahongxi/whatsmars</url> <url>https://github.com/javahongxi/whatsmars</url>
<connection>https://github.com/javahongxi/whatsmars.git</connection> <connection>scm:git:https://github.com/javahongxi/whatsmars.git</connection>
<developerConnection>scm:git:https://github.com/javahongxi/whatsmars.git</developerConnection>
<tag>HEAD</tag>
</scm> </scm>
<build> <build>
......
package org.hongxi.whatsmars.rabbitmq;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.QueueingConsumer;
/**
* Created by shenhongxi on 2017/9/8.
*/
public class Consumer {
public static void main(String[] args) throws Exception {
String queueName = "TestQueue";
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("127.0.0.1");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(queueName, false, false, false, null);
System.out.println(" [*] Waiting for messages...");
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(queueName, true, consumer);
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println(" [x] Received '" + message + "'");
}
}
}
package org.hongxi.whatsmars.rabbitmq;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
/**
* Created by shenhongxi on 2017/9/8.
*/
public class Producer {
public static void main(String[] args) throws Exception {
String queueName = "TestQueue";
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("127.0.0.1");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(queueName, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", queueName, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
}
}
...@@ -81,6 +81,11 @@ ...@@ -81,6 +81,11 @@
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
</dependency> </dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.hongxi</groupId> <groupId>org.hongxi</groupId>
<artifactId>whatsmars-common</artifactId> <artifactId>whatsmars-common</artifactId>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册