本文整理汇总了Java中com.rabbitmq.client.QueueingConsumer.Delivery方法的典型用法代码示例。如果您正苦于以下问题:Java QueueingConsumer.Delivery方法的具体用法?Java QueueingConsumer.Delivery怎么用?Java QueueingConsumer.Delivery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rabbitmq.client.QueueingConsumer
的用法示例。
在下文中一共展示了QueueingConsumer.Delivery方法的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.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();
}
}
示例2: 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++;
}
}
示例3: 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);
}
}
示例4: 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();
}
示例5: call
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public byte[] call(String methodName, String message) throws Exception {
byte[] response = null;
String corrId = UUID.randomUUID().toString();
BasicProperties props = new BasicProperties
.Builder()
.correlationId(corrId)
.replyTo(replyQueueName)
.build();
channel.basicPublish("", REQUEST_QUEUE_NAME, props, message.getBytes("UTF-8"));
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
if (delivery.getProperties().getCorrelationId().equals(corrId)) {
response = delivery.getBody();
break;
}
}
return response;
}
示例6: call
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public String call(String message) throws Exception {
String response = null;
String corrId = UUID.randomUUID().toString();
BasicProperties props = new BasicProperties.Builder().correlationId(corrId).replyTo(replyQueueName).build();
channel.basicPublish("", requestQueueName, props, message.getBytes("UTF-8"));
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
if (delivery.getProperties().getCorrelationId().equals(corrId)) {
response = new String(delivery.getBody(), "UTF-8");
break;
}
}
return response;
}
示例7: call
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public String call(String message) throws Exception {
String response;
String corrId = UUID.randomUUID().toString();
BasicProperties props = new BasicProperties
.Builder()
.correlationId(corrId)
.replyTo(replyQueueName)
.build();
channel.basicPublish("", requestQueueName, props, message.getBytes("UTF-8"));
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
if (delivery.getProperties().getCorrelationId().equals(corrId)) {
response = new String(delivery.getBody(), "UTF-8");
break;
}
}
return response;
}
示例8: 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);
}
}
示例9: 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);
}
}
示例10: 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("order.q", true, consumer);
while (true) {
QueueingConsumer.Delivery msg = consumer.nextDelivery();
String orderType = msg.getProperties().getHeaders().get("type").toString();
String orderItem = new String(msg.getBody());
processor.get(orderType).processOrder(orderItem);
Thread.sleep(2000);
}
}
示例11: 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);
}
}
示例12: execute
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public void execute() throws Exception {
Channel channel = AMQPCommon.connect();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume("order.q", true, consumer);
displayCache();
while (true) {
QueueingConsumer.Delivery msg = consumer.nextDelivery();
String order = new String(msg.getBody());
System.out.println("order received: " + order);
placeOrder(order);
sendEvent(channel, order);
displayCache();
}
}
示例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.basicQos(1);
channel.basicConsume("trade.eq.q", false, consumer);
while (true) {
QueueingConsumer.Delivery msg = consumer.nextDelivery();
System.out.println("message received: " + new String(msg.getBody()));
Thread.sleep(2000);
channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
}
}
示例14: readOneMessage
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
/***
* getParam().getWaitTime() 指定消息池为空时的堵塞超时
*
*/
@Override
public String readOneMessage()
{
try
{
channel.basicConsume(getParam().getQueue(), false, consumer);
QueueingConsumer.Delivery delivery = consumer.nextDelivery(getParam().getWaitTime());
if (delivery != null)
{
deliveryTag = delivery != null ? delivery.getEnvelope().getDeliveryTag() : deliveryTag;
String msg = getMessageContent(delivery);
return msg;
}
else
return null;
}
catch (IOException | ShutdownSignalException | ConsumerCancelledException | InterruptedException e)
{
throw new MqReceiveException(e);
}
}
示例15: main
import com.rabbitmq.client.QueueingConsumer; //导入方法依赖的package包/类
public static void main(String[] argv)
throws java.io.IOException,
java.lang.InterruptedException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
String queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, EXCHANGE_NAME, "");
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
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 + "'");
}
}