
io.latent.storm.rabbitmq.Message Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of storm-rabbitmq Show documentation
Show all versions of storm-rabbitmq Show documentation
A library of tools for interacting with RabbitMQ from Storm.
package io.latent.storm.rabbitmq;
import com.rabbitmq.client.QueueingConsumer;
import java.util.Date;
import java.util.Map;
public class Message {
public static final Message NONE = new None();
private final byte[] body;
public Message(byte[] body) {
this.body = body;
}
public static Message forDelivery(QueueingConsumer.Delivery delivery) {
return (delivery != null) ? new DeliveredMessage(delivery) : NONE;
}
public static Message forSending(byte[] body) {
return (body != null) ? new Message(body) : NONE;
}
public byte[] getBody() {
return body;
}
public static class DeliveredMessage extends Message {
private final boolean redelivery;
private final long deliveryTag;
private final String routingKey;
private final String exchange;
private final String className;
private final String clusterId;
private final String contentEncoding;
private final String contentType;
private final String correlationId;
private final Integer deliveryMode;
private final String expiration;
private final Map headers;
private final String messageId;
private final Integer priority;
private final String replyTo;
private final Date timestamp;
private final String type;
private final String userId;
private DeliveredMessage(QueueingConsumer.Delivery delivery) {
super(delivery.getBody());
redelivery = delivery.getEnvelope().isRedeliver();
deliveryTag = delivery.getEnvelope().getDeliveryTag();
routingKey = delivery.getEnvelope().getRoutingKey();
exchange = delivery.getEnvelope().getExchange();
className = delivery.getProperties().getClassName();
clusterId = delivery.getProperties().getClusterId();
contentEncoding = delivery.getProperties().getContentEncoding();
contentType = delivery.getProperties().getContentType();
correlationId = delivery.getProperties().getCorrelationId();
deliveryMode = delivery.getProperties().getDeliveryMode();
expiration = delivery.getProperties().getExpiration();
headers = delivery.getProperties().getHeaders();
messageId = delivery.getProperties().getMessageId();
priority = delivery.getProperties().getPriority();
replyTo = delivery.getProperties().getReplyTo();
timestamp = delivery.getProperties().getTimestamp();
type = delivery.getProperties().getType();
userId = delivery.getProperties().getUserId();
}
public boolean isRedelivery() { return redelivery; }
public long getDeliveryTag() { return deliveryTag; }
public String getRoutingKey() { return routingKey; }
public String getExchange() { return exchange; }
public String getClassName() { return className;}
public String getClusterId(){ return clusterId; }
public String getContentEncoding() { return contentEncoding; }
public String getContentType() { return contentType; }
public String getCorrelationId() { return correlationId; }
public Integer getDeliveryMode() { return deliveryMode; }
public String getExpiration() { return expiration; }
public Map getHeaders() { return headers; }
public String getMessageId() { return messageId; }
public Integer getPriority() { return priority; }
public String getReplyTo() { return replyTo; }
public Date getTimestamp() { return timestamp; }
public String getType() { return type; }
public String getUserId() { return userId; }
}
public static class None extends Message {
private None() {
super(null);
}
@Override
public byte[] getBody() { throw new UnsupportedOperationException(); };
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy