当前位置: 首页>>代码示例>>Java>>正文


Java QueueingConsumer.Delivery方法代码示例

本文整理汇总了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();
	}			
}
 
开发者ID:wmr513,项目名称:reactive,代码行数:21,代码来源:AMQPInvoicingApp.java

示例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++;
	}			
}
 
开发者ID:wmr513,项目名称:reactive,代码行数:19,代码来源:AMQPConsumer.java

示例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);
	}
}
 
开发者ID:pudoj,项目名称:june.mq,代码行数:40,代码来源:RPCServer.java

示例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();
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:27,代码来源:RabbitMqReceiver.java

示例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;
}
 
开发者ID:FiviumAustralia,项目名称:RNSH-Pilot-FHIR-Service,代码行数:23,代码来源:RPCClient.java

示例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;
}
 
开发者ID:hobbit-project,项目名称:platform,代码行数:19,代码来源:TestRPCClient.java

示例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;
}
 
开发者ID:hobbit-project,项目名称:platform,代码行数:23,代码来源:StorageServiceChannel.java

示例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);
	}			
}
 
开发者ID:wmr513,项目名称:reactive,代码行数:16,代码来源:AMQPThreadDispatcher.java

示例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);
	}			
}
 
开发者ID:wmr513,项目名称:reactive,代码行数:14,代码来源:AMQPThreadConsumer.java

示例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);
	}			
}
 
开发者ID:wmr513,项目名称:reactive,代码行数:14,代码来源:AMQPRouter.java

示例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);
	}			
}
 
开发者ID:wmr513,项目名称:reactive,代码行数:12,代码来源:AMQPBookConsumer.java

示例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();
	}					
}
 
开发者ID:wmr513,项目名称:reactive,代码行数:16,代码来源:AMQPOrderEntryApp.java

示例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);
	}			
}
 
开发者ID:wmr513,项目名称:reactive,代码行数:14,代码来源:AMQPContConsumer.java

示例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);
  }
}
 
开发者ID:iisi-nj,项目名称:GemFireLite,代码行数:26,代码来源:RabbitMqReceiver.java

示例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 + "'");
    }
}
 
开发者ID:anishathalye,项目名称:gitlive,代码行数:26,代码来源:DeliveryBoy.java


注:本文中的com.rabbitmq.client.QueueingConsumer.Delivery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。