本文整理汇总了Java中com.rabbitmq.client.QueueingConsumer.Delivery类的典型用法代码示例。如果您正苦于以下问题:Java Delivery类的具体用法?Java Delivery怎么用?Java Delivery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Delivery类属于com.rabbitmq.client.QueueingConsumer包,在下文中一共展示了Delivery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: runListener
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入依赖的package包/类
private void runListener(String queueName, final OutputStream os) throws Exception {
if (queueName != null) {
channel.queueDeclare(queueName, true, false, false, null);
} else {
queueName = channel.queueDeclare().getQueue();
}
channel.queueBind(queueName, exchangeName, "");
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(queueName, false, consumer);
int c = 0;
while (true) {
Delivery d = consumer.nextDelivery(5000);
c += 1;
if (d != null) {
os.write(d.getBody());
channel.basicAck(d.getEnvelope().getDeliveryTag(), true);
}
if (d == null || c > 1000) {
os.flush();
c = 0;
}
}
}
示例3: main
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
if (args.length < 2) {
System.err.println("Usage: " + RMQSpout.class.getCanonicalName() + " <rmquri> <exchange> [queuename] ");
return;
}
RMQSpout rmq;
if (args.length == 2) {
rmq = new RMQSpout(args[0], args[1]);
} else {
rmq = new RMQSpout(args[0], args[3]);
}
rmq.connect();
while (true) {
Delivery d = rmq.consumer.nextDelivery();
System.out.println(new String(d.getBody()));
rmq.channel.basicAck(d.getEnvelope().getDeliveryTag(), false);
}
}
示例4: 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);
}
}
示例5: RabbitSupplier
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入依赖的package包/类
RabbitSupplier( RabbitConnection connection, String queueName, String bindTopic, String bindRoutingKey,
Consumer<Delivery> optionalConsumer,
boolean durable,
Map<String, Object> queueProperties )
{
this.connection = Objects.requireNonNull( connection );
this.queueName = Objects.requireNonNull( queueName );
this.bindTopic = bindTopic;
this.bindRoutingKey = bindRoutingKey;
this.durable = durable;
this.optionalConsumer = optionalConsumer;
supplier = optionalConsumer == null ? new BlockingSupplierConsumer<>( 1 ) : null;
if( durable ) {
this.queueProperties = queueProperties == null ? new HashMap<>() : queueProperties;
this.queueProperties.putIfAbsent( "x-message-ttl", DEFAULT_TTL );
}
else {
// queue properties are optiona, so null is valid. If empty then replace with null
this.queueProperties = (queueProperties == null || queueProperties.isEmpty()) ? null : queueProperties;
}
// Enable parking
if( this.queueProperties != null && this.queueProperties.containsKey( "internal-park-queue" ) ) {
parked = true;
parkDelay = (Long) this.queueProperties.remove( "internal-park-queue" );
parkQueueName = queueName + "$park";
}
else {
parked = false;
parkDelay = 0L;
parkQueueName = null;
}
}
示例6: processNextMessage
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入依赖的package包/类
private void processNextMessage()
throws IOException,
InterruptedException
{
final QueueingConsumer.Delivery delivery = getQueueingConsumer().
nextDelivery();
try {
if( optionalConsumer == null ) {
supplier.accept( delivery.getBody() );
}
else {
optionalConsumer.accept( delivery );
}
// ack as we have handled it safely
channel.basicAck( delivery.getEnvelope().
getDeliveryTag(), false );
}
catch( Exception ex ) {
// nack and don't requeue
getChannel().
basicNack( delivery.getEnvelope().
getDeliveryTag(), false, false );
}
}
示例7: 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");
}
示例8: nextTuple
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入依赖的package包/类
public void nextTuple() {
try {
Delivery d = consumer.nextDelivery(0);
if (d != null) {
long tag = d.getEnvelope().getDeliveryTag();
int an_id = r.nextInt();
out_id.put(an_id, tag);
collector.emit(new Values(d.getBody()), an_id);
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
示例9: 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();
}
}
示例10: receiveMessage
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入依赖的package包/类
@Override
public final Reply receiveMessage(Request message) throws IOException, ProActiveException {
RpcReusableChannel channel = getRpcReusableChannel();
try {
if (logger.isDebugEnabled()) {
logger.debug(String.format("AMQP RO sending %s to %s, on exchange %s, queue %s", message
.getMethodName(), remoteObjectURL, rpcExchangeName, queueName));
}
String replyQueue = channel.getReplyQueue();
byte[] messageBody = ObjectToByteConverter.ProActiveObjectStream.convert(message);
channel.getChannel().basicPublish(rpcExchangeName, queueName,
new BasicProperties.Builder().replyTo(replyQueue).build(), messageBody);
while (true) {
Delivery delivery = channel.getReplyQueueConsumer().nextDelivery(replyTimeout);
if (delivery != null) {
Reply reply = (Reply) ByteToObjectConverter.ProActiveObjectStream.convert(delivery
.getBody());
if (logger.isDebugEnabled()) {
logger.debug(String.format(
"AMQP RO received response of message %s to %s, on exchange %s, queue %s",
message.getMethodName(), remoteObjectURL, rpcExchangeName, queueName));
}
channel.returnChannel();
return reply;
} else {
// if didn't receive reply after timeout expired then check that remote object server still exists
checkTargetObjectExists();
}
}
} catch (Throwable e) {
channel.close();
throw new IOException(String.format("AMQP cannot send %s to %s, on exchange %s, queue %s",
message.getMethodName(), remoteObjectURL, rpcExchangeName, queueName), e);
}
}
示例11: startup
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入依赖的package包/类
@Override
public void startup() {
//Delivery Actor
ActorRef delivery = system.actorOf(Props.create(DeliveryActor.class), "delivery");
system.eventStream().subscribe(delivery, Delivery.class);
//Listening Actor
system.actorOf(Props.create(ListeningActor.class), "listening");
}
示例12: buildMsgProcessingTask
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入依赖的package包/类
@Override
protected Runnable buildMsgProcessingTask(Delivery delivery) {
return new MsgProcessingTask(delivery, this);
}
示例13: MsgProcessingTask
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入依赖的package包/类
public MsgProcessingTask(Delivery delivery, ResponseHandler responseHandler) {
this.delivery = delivery;
this.responseHandler = responseHandler;
}
示例14: DeliveryProcessing
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入依赖的package包/类
public DeliveryProcessing(StorageService storage, Delivery delivery, RabbitQueue queue) {
this.storage = storage;
this.delivery = delivery;
this.queue = queue;
}
示例15: process
import com.rabbitmq.client.QueueingConsumer.Delivery; //导入依赖的package包/类
public void process(Delivery delivery) throws IOException {
toProcess.addLast(delivery);
}