All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.bitcoco.jsk.message.MessageEventBody Maven / Gradle / Ivy

The newest version!
package ca.bitcoco.jsk.message;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.time.LocalDateTime;

/**
 * Core message event body format
 * Used as message broadcast/subscribe event body
 * @author Jiangqi Li
 */
public class MessageEventBody {

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
    private LocalDateTime timestamp;
    private String source;   //“packageName”/”serviceName”
    private String event;
    private String contentType = "application/json";
    private T data;


    public MessageEventBody() {

    }

    /**
     * Create an responseBody used in ResponseEntity.
     *
     * @param data  coreResponse data.
     * @param source String source.
     * @param event   String event.
     * @param contentType String contentType.
     */
    private MessageEventBody(T data, String source, String event, String contentType) {
        this.data = data;
        this.source = source;
        this.event = event;
        if(contentType != null && !contentType.isEmpty()){
            this.contentType = contentType;
        }
    }

    public static  MessageEventBody data(T data, String source, String event, String contentType) {
        return new MessageEventBody(data, source, event, contentType);
    }

    public static  MessageEventBody data(T data, String source, String event) {
        return new MessageEventBody(data, source, event, null);
    }

    public LocalDateTime getTimestamp() {
        return timestamp;
    }


    public String getSource() {
        return source;
    }

    public MessageEventBody setSource(String source) {
        this.source = source;
        return this;
    }

    public String getEvent() {
        return event;
    }

    public MessageEventBody setEvent(String event) {
        this.event = event;
        return this;
    }

    public String getContentType() {
        return contentType;
    }

    public MessageEventBody setContentType(String contentType) {
        this.contentType = contentType;
        return this;
    }

    public T getData() {
        return data;
    }

    public MessageEventBody setData(T data) {
        this.data = data;
        return this;
    }




}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy