pl.allegro.tech.hermes.common.message.wrapper.MessageMetadata Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hermes-common Show documentation
Show all versions of hermes-common Show documentation
Fast and reliable message broker built on top of Kafka.
package pl.allegro.tech.hermes.common.message.wrapper;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Objects;
import static java.util.Optional.ofNullable;
@JsonIgnoreProperties(ignoreUnknown = true)
public class MessageMetadata {
private final long timestamp;
private final String id;
private final Map externalMetadata;
@JsonCreator
public MessageMetadata(@JsonProperty("timestamp") long timestamp,
@JsonProperty("id") String id,
@JsonProperty("externalMetadata") Map externalMetadata) {
this.id = id;
this.timestamp = timestamp;
this.externalMetadata = ofNullable(externalMetadata).orElseGet(ImmutableMap::of);
}
public MessageMetadata(long timestamp, Map externalMetadata) {
this(timestamp, "", externalMetadata);
}
public String getId() {
return id;
}
public long getTimestamp() {
return timestamp;
}
public Map getExternalMetadata() {
return ImmutableMap.copyOf(externalMetadata);
}
@Override
public int hashCode() {
return Objects.hash(id, timestamp);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final MessageMetadata other = (MessageMetadata) obj;
return Objects.equals(this.id, other.id)
&& Objects.equals(this.timestamp, other.timestamp);
}
}