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

de.otto.synapse.message.TextMessage Maven / Gradle / Ivy

Go to download

A library used at otto.de to implement Spring Boot based event-sourcing microservices.

There is a newer version: 0.33.1
Show newest version
package de.otto.synapse.message;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * A {@code Message} that is used by Synapse for messages with String payloads.
 *
 */
public class TextMessage extends Message {


    private static final long serialVersionUID = 4270568972655971096L;

    protected TextMessage(final @Nonnull Key key,
                          final @Nonnull Header header,
                          final @Nullable String payload) {
        super(key, header, payload);
    }

    /**
     * Factory method used to create a {@code TextMessage} from another {@link Message Message<String>}
     *
     * @param message a message with payload-type {@code String}
     * @return TextMessage
     */
    @Nonnull
    public static TextMessage of(final @Nonnull Message message) {
        return new TextMessage(message.getKey(), message.getHeader(), message.getPayload());
    }

    /**
     * Factory method used to create a {@code TextMessage} from key, header and payload parameters.
     *
     * @param key Key of the created message
     * @param header Header of the created message
     * @param payload Payload of the created message
     * @return TextMessage
     */
    @Nonnull
    public static TextMessage of(final @Nonnull Key key,
                                 final @Nonnull Header header,
                                 final @Nullable String payload) {
        return new TextMessage(key, header, payload);
    }

    /**
     * Factory method used to create a {@code TextMessage} from key, header and payload parameters.
     *
     * @param key Key of the created message
     * @param header Header of the created message
     * @param payload Payload of the created message
     * @return TextMessage
     */
    @Nonnull
    public static TextMessage of(final @Nonnull String key,
                                 final @Nonnull Header header,
                                 final @Nullable String payload) {
        return new TextMessage(Key.of(key), header, payload);
    }

    /**
     * Factory method used to create a {@code TextMessage} from key and payload parameters.
     *
     * @param key Key of the created message
     * @param payload Payload of the created message
     * @return TextMessage
     */
    @Nonnull
    public static TextMessage of(final @Nonnull Key key,
                                 final @Nullable String payload) {
        return new TextMessage(key, Header.of(), payload);
    }

    /**
     * Factory method used to create a {@code TextMessage} from key and payload parameters.
     *
     * @param key Key of the created message
     * @param payload Payload of the created message
     * @return TextMessage
     */
    public static TextMessage of(final @Nonnull String key,
                                 final @Nullable String payload) {
        return new TextMessage(Key.of(key), Header.of(), payload);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy