本文整理汇总了Java中com.rabbitmq.client.QueueingConsumer.nextDelivery方法的典型用法代码示例。如果您正苦于以下问题:Java QueueingConsumer.nextDelivery方法的具体用法?Java QueueingConsumer.nextDelivery怎么用?Java QueueingConsumer.nextDelivery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rabbitmq.client.QueueingConsumer
的用法示例。
在下文中一共展示了QueueingConsumer.nextDelivery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Channel channel = AMQPCommon.connect();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicQos(1);
channel.basicConsume("trade.eq.q", false, consumer);
int numMsgs = args.length > 0 ? new Integer(args[0]).intValue() : 1;
for (int i=0; i<numMsgs; i++) {
QueueingConsumer.Delivery msg = consumer.nextDelivery();
System.out.println("message received: " + new String(msg.getBody()));
Thread.sleep(1000);
channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
}
AMQPCommon.close(channel);
}
示例2: main
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
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 + "'");
}
}
示例3: execute
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public void execute() throws Exception {
Channel channel = AMQPCommon.connect();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume("trade.request.q", true, consumer);
int index = 0;
while (true) {
QueueingConsumer.Delivery message = consumer.nextDelivery();
String msg = new String(message.getBody());
System.out.println("processing trade: " + msg);
String newMsg = "response";
byte[] bmsg = newMsg.getBytes();
Thread.sleep(responseTimes.get(index));
channel.basicPublish("", "trade.response.q", null, bmsg);
index++;
}
}
示例4: execute
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public void execute() throws Exception {
Channel channel = AMQPCommon.connect();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume("workflow.q", true, consumer);
while (true) {
QueueingConsumer.Delivery message = consumer.nextDelivery();
String msg = new String(message.getBody());
System.out.println("message received: " + msg);
String newMsg = msg.substring(0, msg.indexOf(" shares"));
byte[] bmsg = newMsg.getBytes();
System.out.println("Trade fixed: " + newMsg);
channel.basicPublish("", "trade.eq.q", null, bmsg);
}
}
示例5: execute
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public void execute() throws Exception {
Channel channel = AMQPCommon.connect();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume("trade.eq.q", true, consumer);
QueueingConsumer.Delivery msg = null;
while (true) {
try {
msg = consumer.nextDelivery();
String message = new String(msg.getBody());
System.out.println("message received: " + message);
String[] parts = message.split(",");
long shares = new Long(parts[2]).longValue();
Thread.sleep(1000);
} catch (Exception e) {
System.out.println("error with trade: " + e.getMessage());
System.out.println("sending to workflow");
channel.basicPublish("", "workflow.q", null, msg.getBody());
}
}
}
示例6: start
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public void start(Connection connection) {
try {
active = true;
Channel channel = connection.createChannel();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicQos(1);
channel.basicConsume("trade.eq.q", false, consumer);
while (active) {
QueueingConsumer.Delivery msg = consumer.nextDelivery();
System.out.println("message received: " + new String(msg.getBody()));
Thread.sleep(1000);
channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
}
channel.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: main
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Channel channel = AMQPCommon.connect();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume("sync.q", true, consumer);
displayCache();
while (true) {
QueueingConsumer.Delivery msg = consumer.nextDelivery();
String body = new String(msg.getBody());
System.out.println("synchronize message received: " + body);
String[] parts = body.split(",");
String cust = parts[0];
long price = new Long(parts[2]).longValue();
price = (long)(price - (price*.10));
long cost = new Long(cache.get(cust).split(",")[1]).longValue() + price;
long qty = new Long(cache.get(cust).split(",")[0]).longValue() + 1;
cache.put(cust, qty + "," + cost);
displayCache();
}
}
示例8: main
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
// setRemoteConnectionFactory(factory);
setLocalConnectionFactory(factory);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer);
while (true) {
Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println(" [x] Received '" + message + "'");
}
}
示例9: main
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
/**
* @param args
* @throws TimeoutException
* @throws IOException
* @throws InterruptedException
* @throws ConsumerCancelledException
* @throws ShutdownSignalException
*/
public static void main(String[] args) throws IOException, TimeoutException, ShutdownSignalException,
ConsumerCancelledException, InterruptedException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(host);
factory.setUsername(username);
factory.setPassword(password);
factory.setPort(port);
factory.setVirtualHost(virtualHost);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null);
channel.basicQos(1);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(RPC_QUEUE_NAME, false, consumer);
System.out.println("RPCServer Awating RPC request");
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
BasicProperties props = delivery.getProperties();
BasicProperties replyProps = new AMQP.BasicProperties.Builder().correlationId(props.getCorrelationId())
.build();
String message = new String(delivery.getBody(), "UTF-8");
int n = Integer.parseInt(message);
System.out.println("RPCServer fib(" + message + ")");
String response = "" + fib(n);
channel.basicPublish("", props.getReplyTo(), replyProps, response.getBytes());
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
}
}
示例10: startSyncReceiveThread
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
private void startSyncReceiveThread(final QueueingConsumer consumer, final boolean autoAck, final BindingVo binding) {
syncReceiveThread = new SyncReceiveThread() {
@Override
public void run() {
log.info("start listen to the " + typeStr + "[" + queue.getName() + "].");
while (running) {
try {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
XCO xcoMessage = getMessage(delivery.getBody());
log.info("received a message from " + typeStr + "[" + queue.getName() + "]: " + xcoMessage);
boolean result = exec(service, xcoMessage, binding);
if (!autoAck && result) {
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
}
} catch (ShutdownSignalException e) {
// TODO 可能会出现断链的问题
e.printStackTrace();
} catch (Throwable e) {
log.error("listen to the [" + queue.getName() + "] error.", e);
}
}
closed = true;
}
};
syncReceiveThread.start();
}
示例11: dispatchMessages
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public void dispatchMessages() throws Exception {
Channel channel = AMQPCommon.connect();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicQos(1);
channel.basicConsume("trade.eq.q", false, consumer);
while (true) {
QueueingConsumer.Delivery msg = consumer.nextDelivery();
channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
new Thread(new POJOThreadProcessor(
this, new String(msg.getBody()))).start();
numThreads++;
System.out.println("Threads: " + numThreads);
}
}
示例12: main
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Channel channel = AMQPCommon.connect();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicQos(1);
channel.basicConsume("trade.eq.q", false, consumer);
while (true) {
QueueingConsumer.Delivery msg = consumer.nextDelivery();
Thread.sleep(2000);
System.out.println("Trade placed: " + new String(msg.getBody()));
channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
}
}
示例13: main
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Channel channel = AMQPCommon.connect();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume("movie.q", true, consumer);
while (true) {
QueueingConsumer.Delivery msg = consumer.nextDelivery();
System.out.println("PROCESSING MOVIE ORDER: " + new String(msg.getBody()));
Thread.sleep(2000);
}
}
示例14: main
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Channel channel = AMQPCommon.connect();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume("book.q", true, consumer);
while (true) {
QueueingConsumer.Delivery msg = consumer.nextDelivery();
System.out.println("PROCESSING BOOK ORDER: " + new String(msg.getBody()));
Thread.sleep(2000);
}
}
示例15: main
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Channel channel = AMQPCommon.connect();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume("music.q", true, consumer);
while (true) {
QueueingConsumer.Delivery msg = consumer.nextDelivery();
System.out.println("PROCESSING MUSIC ORDER: " + new String(msg.getBody()));
Thread.sleep(2000);
}
}