本文整理汇总了Java中com.rabbitmq.client.Envelope.getDeliveryTag方法的典型用法代码示例。如果您正苦于以下问题:Java Envelope.getDeliveryTag方法的具体用法?Java Envelope.getDeliveryTag怎么用?Java Envelope.getDeliveryTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rabbitmq.client.Envelope
的用法示例。
在下文中一共展示了Envelope.getDeliveryTag方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleDelivery
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
@Override
public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException {
if(body != null) {
try {
// resolve the returned message
long deliveryTag = envelope.getDeliveryTag();
String message = new String(body, "UTF-8");
LOG.info("Task received: consumerTag=" + consumerTag + ", deliveryTag=" + deliveryTag + ", message=" + message);
JSONObject taskReq = JSONObject.parseObject(message);
if(!taskReq.isEmpty()) {
long id = messageIdGenerator.incrementAndGet();
WaitingTask task = new WaitingTask(id, taskReq, getChannel(), deliveryTag);
waitingTasks.putLast(task);
LOG.info("Add task to waiting queue: " + task);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例2: handleDelivery
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
@Override
public void handleDelivery(String consumer_Tag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException
{
long tag = envelope.getDeliveryTag();
if (envelope.isRedeliver() && (recoveredTags.contains(tag) || pendingAck.contains(tag))) {
if (recoveredTags.contains(tag)) {
pendingAck.add(tag);
}
return;
}
// Acknowledgements are sent at the end of the window after adding to idempotency manager
pendingAck.add(tag);
holdingBuffer.add(new KeyValPair<Long, byte[]>(tag, body));
logger.debug("Received Async message: {} buffersize: {} ", new String(body), holdingBuffer.size());
}
示例3: handleDelivery
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
/**
* Handles a message delivery from the broker.
*/
@Override
public void handleDelivery(String consumerTag, Envelope envelope,
BasicProperties properties, byte[] body) throws IOException {
LOG.debug("Consumer: {} Received handle delivery", consumerTag);
Message message = new Message(properties, body, envelope.getExchange(),
envelope.getRoutingKey(), envelope.getDeliveryTag());
LOG.info("Consumer: {} Received message: {}", consumerTag,
envelope.getDeliveryTag());
handleMessage(message);
_channel.basicAck(envelope.getDeliveryTag(), true);
}
示例4: beginSubscriptionThread
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
@Override
public void beginSubscriptionThread() throws InterruptedException, IOException {
DefaultConsumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag,
Envelope envelope,
AMQP.BasicProperties properties,
byte[] body)
throws IOException {
long deliveryTag = envelope.getDeliveryTag();
LOG.info("[RabbitMQEventConsumer {}] Received Message: {}",
Thread.currentThread().getId(), new String(body));
Gson gson = new Gson();
@SuppressWarnings("unchecked")
final CoordinationEntryEvent<K> event = gson.fromJson(new String(body), CoordinationEntryEvent.class);
routeEventToListeners(event);
channel.basicAck(deliveryTag, false);
}
};
consumerTag = channel.basicConsume(queueName, false, consumer);
}
示例5: publishToPoisonQueue
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
/**
* Send all unacknowledged messages to poison queue, up-to and including this one
* @throws IOException
*/
private void publishToPoisonQueue(Envelope envelope
, AMQP.BasicProperties properties
, String reason
, byte[] body
, boolean multiple) throws IOException {
if (!multiple) {
super.publishToPoisonQueue(envelope, properties, reason, body);
return;
}
Iterator<AMQPMessageBundle> messages = unacknowledgedMessages.values().iterator();
long deliveryTag = envelope.getDeliveryTag();
while (messages.hasNext()) {
AMQPMessageBundle next = messages.next();
if (next.getEnvelope().getDeliveryTag() > deliveryTag) {
break;
}
super.publishToPoisonQueue(next.getEnvelope(), next.getBasicProperties(), reason, next.getBody());
}
}
示例6: createConsumer
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
private Consumer createConsumer(final Channel channel)
{
return new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag,
Envelope envelope,
AMQP.BasicProperties properties,
byte[] body)
throws IOException
{
long deliveryTag = envelope.getDeliveryTag();
String row[] = ExportOnServerVerifier.RoughCSVTokenizer.tokenize(new String(body, Charsets.UTF_8));
if (row.length != 29) {
return;
}
ExportOnServerVerifier.ValidationErr err = null;
try {
err = ExportOnServerVerifier.verifyRow(row);
} catch (ExportOnServerVerifier.ValidationErr validationErr) {
validationErr.printStackTrace();
}
if (err != null) {
System.out.println("ERROR in validation: " + err.toString());
}
if (++m_verifiedRows % VALIDATION_REPORT_INTERVAL == 0) {
System.out.println("Verified " + m_verifiedRows + " rows.");
}
channel.basicAck(deliveryTag, false);
}
};
}
示例7: handleDelivery
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws IOException {
if (bindAckToRequest) {
this.deliveryTag = envelope.getDeliveryTag();
}
doOnNext.accept(QueueSignal.from(body, consumerTag, envelope, properties));
}
示例8: handleDelivery
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
@Override public void handleDelivery(String consumerTag,
Envelope envelope,
AMQP.BasicProperties basicProperties,
byte[] body) throws IOException {
Message message = new Message();
try {
ThriftUtils.createThriftFromBytes(body, message);
TBase event = null;
String gatewayId = null;
long deliveryTag = envelope.getDeliveryTag();
if (message.getMessageType().equals(MessageType.LAUNCHPROCESS)) {
ProcessSubmitEvent processSubmitEvent = new ProcessSubmitEvent();
ThriftUtils.createThriftFromBytes(message.getEvent(), processSubmitEvent);
log.info(" Message Received with message id '" + message.getMessageId()
+ " and with message type:" + message.getMessageType() + ", for processId:" +
processSubmitEvent.getProcessId() + ", expId:" + processSubmitEvent.getExperimentId());
event = processSubmitEvent;
gatewayId = processSubmitEvent.getGatewayId();
MessageContext messageContext = new MessageContext(event, message.getMessageType(),
message.getMessageId(), gatewayId, deliveryTag);
messageContext.setUpdatedTime(AiravataUtils.getTime(message.getUpdatedTime()));
messageContext.setIsRedeliver(envelope.isRedeliver());
handler.onMessage(messageContext);
} else {
log.error("{} message type is not handle in ProcessLaunch Subscriber. Sending ack for " +
"delivery tag {} ", message.getMessageType().name(), deliveryTag);
sendAck(deliveryTag);
}
} catch (TException e) {
String msg = "Failed to de-serialize the thrift message, from routing keys:" + envelope.getRoutingKey();
log.warn(msg, e);
}
}
示例9: handleDelivery
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
@Override
public void handleDelivery(String consumerTag,
Envelope envelope,
AMQP.BasicProperties properties,
byte[] body) throws IOException {
Message message = new Message();
try {
ThriftUtils.createThriftFromBytes(body, message);
long deliveryTag = envelope.getDeliveryTag();
if (message.getMessageType() == MessageType.EXPERIMENT || message.getMessageType() == MessageType.EXPERIMENT_CANCEL) {
TBase event = null;
String gatewayId = null;
ExperimentSubmitEvent experimentEvent = new ExperimentSubmitEvent();
ThriftUtils.createThriftFromBytes(message.getEvent(), experimentEvent);
log.info(" Message Received with message id '" + message.getMessageId()
+ "' and with message type '" + message.getMessageType() + "' for experimentId:" +
" " +
experimentEvent.getExperimentId());
event = experimentEvent;
gatewayId = experimentEvent.getGatewayId();
MessageContext messageContext = new MessageContext(event, message.getMessageType(),
message.getMessageId(), gatewayId, deliveryTag);
messageContext.setUpdatedTime(AiravataUtils.getTime(message.getUpdatedTime()));
messageContext.setIsRedeliver(envelope.isRedeliver());
handler.onMessage(messageContext);
} else {
log.error("{} message type is not handle in ProcessLaunch Subscriber. Sending ack for " +
"delivery tag {} ", message.getMessageType().name(), deliveryTag);
sendAck(deliveryTag);
}
} catch (TException e) {
String msg = "Failed to de-serialize the thrift message, from routing keys:" + envelope.getRoutingKey();
log.warn(msg, e);
}
}
示例10: respond
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
private void respond(AMQPMessageBundle messageBundle, ActionResponse actionResponse) {
//! We can't issue any blocking amqp calls in the context of this method, otherwise
// channel's internal thread(s) will deadlock. Both, basicAck and basicReject are
// asynchronous.
Envelope envelope = messageBundle.getEnvelope();
Long deliveryTag = envelope.getDeliveryTag();
byte[] body = messageBundle.getBody();
AMQP.BasicProperties properties = messageBundle.getBasicProperties();
try {
switch (actionResponse.getAction()) {
case Acknowledge:
ack(deliveryTag);
break;
case RejectAndDiscard:
log.warn("Discarding message, body = " + new String(body));
//! Let the broker know we rejected this message. Then publish this bad boy onto
// the poison queue. Don't bother confirming for two reasons; we don't care, and
// we can't issue blocking calls here.
publishToPoisonQueue(envelope, properties, actionResponse.getReason(), body);
reject(deliveryTag);
break;
case RejectAndRequeue:
log.warn("Received an unknown message, body = " + new String(body));
log.warn("\tAdjusting headers for retry.");
if (!retry(envelope, properties, body)) {
publishToPoisonQueue(envelope, properties, actionResponse.getReason(), body);
}
reject(deliveryTag);
break;
}
} catch (Exception e) {
callback.notifyOfActionFailure(e);
}
}
示例11: respond
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
protected void respond(AMQPMessageBundle messageBundle, ActionResponse actionResponse, boolean multiple) {
//! We can't issue any blocking amqp calls in the context of this method, otherwise
// channel's internal thread(s) will deadlock. Both, basicAck and basicReject are
// asynchronous.
Envelope envelope = messageBundle.getEnvelope();
Long deliveryTag = envelope.getDeliveryTag();
byte[] body = messageBundle.getBody();
AMQP.BasicProperties properties = messageBundle.getBasicProperties();
try {
switch (actionResponse.getAction()) {
case Acknowledge:
ack(deliveryTag, multiple);
break;
case RejectAndDiscard:
log.warn("Discarding message, body = " + new String(body));
//! Let the broker know we rejected this message. Then publish this bad boy onto
// the poison queue. Don't bother confirming for two reasons; we don't care, and
// we can't issue blocking calls here.
publishToPoisonQueue(envelope, properties, actionResponse.getReason(), body, multiple);
reject(deliveryTag, multiple);
break;
case RejectAndRequeue:
log.warn("Received an unknown message, body = " + new String(body));
log.warn("\tAdjusting headers for retry.");
if (!retry(envelope, properties, body, multiple)) {
publishToPoisonQueue(envelope, properties, actionResponse.getReason(), body, multiple);
}
reject(deliveryTag, multiple);
break;
}
} catch (Exception e) {
callback.notifyOfActionFailure(e);
}
}
示例12: handleDelivery
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
long deliveryTag = envelope.getDeliveryTag();
Stopwatch stopwatch = Stopwatch.createStarted();
try {
T message = MAPPER.readValue(body, type);
if (log.isTraceEnabled()) {
log.trace("Received message '{}' with data '{}'.", deliveryTag, new String(body));
}
processor.apply(message);
getChannel().basicAck(deliveryTag, false);
stopwatch.stop();
successCount.mark();
successDuration.update(stopwatch.elapsed(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS);
log.info("Processed {} message '{}' succesfully in {} ms.", type.getSimpleName(), deliveryTag, stopwatch.elapsed(TimeUnit.MILLISECONDS));
} catch (Exception e) {
getChannel().basicNack(deliveryTag, false, true);
stopwatch.stop();
failureCount.mark();
failureDuration.update(stopwatch.elapsed(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS);
log.error("Processing {} message '{}' failed with exception:", type.getSimpleName(), deliveryTag, e);
}
}
示例13: handleDelivery
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
@Override
public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties,
byte[] body) throws IOException {
if (closed)
return;
long deliveryTag = envelope.getDeliveryTag();
channelHandler.maxDeliveryTag = deliveryTag = deliveryTag
+ channelHandler.previousMaxDeliveryTag;
delegate.handleDelivery(
consumerTag,
new Envelope(deliveryTag, envelope.isRedeliver(), envelope.getExchange(),
envelope.getRoutingKey()), properties, body);
}
示例14: HaEnvelope
import com.rabbitmq.client.Envelope; //导入方法依赖的package包/类
public HaEnvelope(long internalChannelId, Envelope internalEnvelope) {
this.deliveryTag = new DeliveryTag(internalChannelId, internalEnvelope.getDeliveryTag());
this.internalEnvelope = internalEnvelope;
}