本文整理汇总了Java中com.rabbitmq.client.QueueingConsumer.Delivery.getBody方法的典型用法代码示例。如果您正苦于以下问题:Java Delivery.getBody方法的具体用法?Java Delivery.getBody怎么用?Java Delivery.getBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rabbitmq.client.QueueingConsumer.Delivery
的用法示例。
在下文中一共展示了Delivery.getBody方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入方法依赖的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 + "'");
}
}
示例2: hasNext
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入方法依赖的package包/类
@Override
public boolean hasNext() throws IOException, CollectionException {
try {
Delivery d = consumer.nextDelivery(timeout * 1000);
if (d == null) {
LOG.info(" [RabbitReader] timout, exiting reader!");
return false;
}
nextDelivery = d.getBody();
deliveryTag = d.getEnvelope().getDeliveryTag();
return true;
} catch (InterruptedException ie) {
LOG.info(" [RabbitReader] timout2, exiting reader!");
return false;
} catch (Exception e) {
throw new CollectionException(e);
}
}
示例3: processDelivery
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入方法依赖的package包/类
private void processDelivery(Delivery delivery) throws Exception {
BasicProperties props = delivery.getProperties();
BasicProperties replyProps = new BasicProperties.Builder().correlationId(props.getCorrelationId()).build();
DataInputStream data = new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(delivery.getBody())));
RenderMode mode = RenderMode.values()[data.readUnsignedByte()];
int width = data.readUnsignedShort();
int height = data.readUnsignedShort();
GameProfile profile = Profiles.readGameProfile(data);
Map<String, String[]> params = Maps.newHashMap();
int len = data.readUnsignedShort();
for (int i = 0; i < len; i++) {
String key = data.readUTF();
String[] val = new String[data.readUnsignedByte()];
for (int v = 0; v < val.length; v++) {
val[v] = data.readUTF();
}
params.put(key, val);
}
byte[] skinData = new byte[data.readInt()];
data.readFully(skinData);
BufferedImage skin = new PngImage().read(new ByteArrayInputStream(skinData), false);
Visage.log.info("Received a job to render a "+width+"x"+height+" "+mode.name().toLowerCase()+" for "+(profile == null ? "null" : profile.getName()));
RenderConfiguration conf = new RenderConfiguration(Type.fromMode(mode), Profiles.isSlim(profile), mode.isTall(), Profiles.isFlipped(profile));
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
byte[] pngBys = draw(conf, width, height, profile, skin, params);
if (Visage.trace) Visage.log.finest("Got png bytes");
parent.channel.basicPublish("", props.getReplyTo(), replyProps, buildResponse(0, pngBys));
if (Visage.trace) Visage.log.finest("Published response");
parent.channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
if (Visage.trace) Visage.log.finest("Ack'd message");
}
示例4: run
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入方法依赖的package包/类
@Override
public void run() {
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "fanout", durable);
DeclareOk ok = channel.queueDeclare(queue_name, durable, false, false, null);
String queueName = ok.getQueue();
channel.queueBind(queueName, EXCHANGE_NAME, "");
System.out.println(" [" + queue_name + "] Waiting for messages. To exit press CTRL+C");
channel.basicQos(1); // 消息分发处理
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(queueName, false, consumer);
while (true) {
Thread.sleep(2000);
Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println(" [" + queue_name + "] Received '" + message + "'");
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
}
} catch (Exception e) {
e.printStackTrace();
}
}