
org.reactivecommons.async.rabbit.RabbitMessage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of async-rabbit Show documentation
Show all versions of async-rabbit Show documentation
Abstract your broker with semantic async messages
The newest version!
package org.reactivecommons.async.rabbit;
import com.rabbitmq.client.Delivery;
import lombok.Data;
import org.reactivecommons.async.commons.communications.Message;
import java.util.HashMap;
import java.util.Map;
@Data
public class RabbitMessage implements Message {
private final byte[] body;
private final Properties properties;
@Data
public static class RabbitMessageProperties implements Properties {
private String contentType;
private String contentEncoding;
private long timestamp;
private long contentLength;
private Map headers = new HashMap<>();
}
public static RabbitMessage fromDelivery(Delivery delivery) {
return new RabbitMessage(delivery.getBody(), createMessageProps(delivery));
}
private static Message.Properties createMessageProps(Delivery msj) {
final RabbitMessage.RabbitMessageProperties properties = new RabbitMessage.RabbitMessageProperties();
if (msj.getProperties().getTimestamp() != null) {
properties.setTimestamp(msj.getProperties().getTimestamp().getTime());
}
properties.setHeaders(msj.getProperties().getHeaders());
properties.setContentType(msj.getProperties().getContentType());
properties.setContentEncoding(msj.getProperties().getContentEncoding());
return properties;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy