Interface SerializedMessageBus

  • All Known Implementing Classes:
    SerializedMessageBusImpl

    public interface SerializedMessageBus
    A SerializedMessageBus enhances a typical MessageBus with serialization and deserialization functionality. It provides methods to send, receive and subscribe to both serialized and not serialized data. It also incorporates the functionality of a MessageFunction by providing functions, that wait on a matching response.
    See Also:
    EventMaid Documentation
    • Method Detail

      • aSerializedMessageBus

        static SerializedMessageBus aSerializedMessageBus​(MessageBus messageBus,
                                                          Serializer requestSerializer,
                                                          Deserializer responseDeserializer)
        Factory method to create a new SerializedMessageBus from the normal MessageBus, a Deserializer and a Serializer.
        Parameters:
        messageBus - the MessageBus to wrap
        requestSerializer - the Serializer to serialize objects being sent on the bus
        responseDeserializer - the Deserializer to deserialize received messages into the required types
        Returns:
        the newly created SerializedMessageBus
      • send

        MessageId send​(EventType eventType,
                       Object data)
        Sends the given data in form of a Map on the MessageBus with the EventType.
        Parameters:
        eventType - the EventType to relate the message to
        data - the data to send
        Returns:
        a unique MessageId for the message
      • send

        MessageId send​(EventType eventType,
                       Object data,
                       CorrelationId correlationId)
        Sends the given data in form of a Map on the MessageBus with the EventType and CorrelationId set.
        Parameters:
        eventType - the EventType to relate the message to
        data - the data to send
        correlationId - the CorrelationId relating to a previous MessageId
        Returns:
        a unique MessageId for the message
      • send

        MessageId send​(EventType eventType,
                       Object data,
                       Object errorData)
        Sends the given data and error data both in form of a Map on the MessageBus with the EventType.
        Parameters:
        eventType - the EventType to relate the message to
        data - the data to send
        errorData - the error data to send
        Returns:
        a unique MessageId for the message
      • send

        MessageId send​(EventType eventType,
                       Object data,
                       Object errorData,
                       CorrelationId correlationId)
        Sends the given data and error data both in form of a Map on the MessageBus with the EventType and CorrelationId.
        Parameters:
        eventType - the EventType to relate the message to
        data - the data to send
        errorData - the error data to send
        correlationId - the CorrelationId relating to a previous MessageId
        Returns:
        a unique MessageId for the message
      • serializeAndSend

        MessageId serializeAndSend​(EventType eventType,
                                   Object data)
        Serializes the data to a Map and then sends it with the EventType on the MessageBus.
        Parameters:
        eventType - the EventType to relate the message to
        data - the data to serialize and send
        Returns:
        a unique MessageId for the message
      • serializeAndSend

        MessageId serializeAndSend​(EventType eventType,
                                   Object data,
                                   CorrelationId correlationId)
        Serializes the data to a Map and then sends it with the EventType and CorrelationId on the MessageBus.
        Parameters:
        eventType - the EventType to relate the message to
        data - the data to serialize and send
        correlationId - the CorrelationId relating to a previous MessageId
        Returns:
        a unique MessageId for the message
      • serializeAndSend

        MessageId serializeAndSend​(EventType eventType,
                                   Object data,
                                   Object errorData)
        Serializes the data and error data to a Map and then sends both with the EventType on the MessageBus.
        Parameters:
        eventType - the EventType to relate the message to
        data - the data to serialize and send
        errorData - the error data to send
        Returns:
        a unique MessageId for the message
      • serializeAndSend

        MessageId serializeAndSend​(EventType eventType,
                                   Object data,
                                   Object errorData,
                                   CorrelationId correlationId)
        Serializes the data and error data to a Map and then sends both with the EventType and CorrelationId on the MessageBus.
        Parameters:
        eventType - the EventType to relate the message to
        data - the data to serialize and send
        errorData - the error data to send
        correlationId - the CorrelationId relating to a previous MessageId
        Returns:
        a unique MessageId for the message
      • invokeAndWaitDeserialized

        <P,​E> PayloadAndErrorPayload<P,​E> invokeAndWaitDeserialized​(EventType eventType,
                                                                                Object data,
                                                                                Class<P> responseClass,
                                                                                Class<E> errorPayloadClass)
                                                                         throws InterruptedException,
                                                                                ExecutionException
        Serializes and sends the data on the MessageBus. Then the methods waits until a response is received or an exception occurred. The response is deserialized into the two given classes.
        Type Parameters:
        P - the type to deserialize the normal response to
        E - the type to deserialize the error response to
        Parameters:
        eventType - the EventType to relate the message to
        data - the error data to send
        responseClass - the class to deserialize the normal response to
        errorPayloadClass - the class to deserialize the error response to
        Returns:
        the deserialized normal and error payload
        Throws:
        InterruptedException - if the waiting Thread is interrupted
        ExecutionException - if the message or response caused an exception
      • invokeAndWaitDeserialized

        <P,​E> PayloadAndErrorPayload<P,​E> invokeAndWaitDeserialized​(EventType eventType,
                                                                                Object data,
                                                                                Class<P> responseClass,
                                                                                Class<E> errorPayloadClass,
                                                                                long timeout,
                                                                                TimeUnit unit)
                                                                         throws InterruptedException,
                                                                                ExecutionException,
                                                                                TimeoutException
        Serializes and sends the data on the MessageBus. Then the methods waits until a response is received, an exception occurred or the timeout expired. The response is deserialized into the two given classes.
        Type Parameters:
        P - the type to deserialize the normal response to
        E - the type to deserialize the error response to
        Parameters:
        eventType - the EventType to relate the message to
        data - the error data to send
        responseClass - the class to deserialize the normal response to
        errorPayloadClass - the class to deserialize the error response to
        timeout - the timeout interval
        unit - the unit to measure the interval in
        Returns:
        the deserialized normal and error payload
        Throws:
        InterruptedException - if the waiting Thread is interrupted
        ExecutionException - if the message or response caused an exception
        TimeoutException - if the timeout expired
      • subscribeDeserialized

        <P,​E> SubscriptionId subscribeDeserialized​(EventType eventType,
                                                         Subscriber<PayloadAndErrorPayload<P,​E>> subscriber,
                                                         Class<P> responseClass,
                                                         Class<E> errorClass)
        Adds the given Subscriber for all messages of the given EventType. The normal and error payload are deserialized into the to given Classes.
        Type Parameters:
        P - the type to deserialize the normal payload into
        E - the type to deserialize the error payload into
        Parameters:
        eventType - the EventType of the messages to receive
        subscriber - the Subscriber to invoke
        responseClass - the Class to deserialize the normal payload into
        errorClass - the Class to deserialize the error payload into
        Returns:
        a SubscriptionId to identify the Subscriber
      • subscribeDeserialized

        <P,​E> SubscriptionId subscribeDeserialized​(CorrelationId correlationId,
                                                         Subscriber<PayloadAndErrorPayload<P,​E>> subscriber,
                                                         Class<P> responseClass,
                                                         Class<E> errorClass)
        Adds the given Subscriber for all messages of the given EventType. The normal and error payload are deserialized into the to given Classes.
        Type Parameters:
        P - the type to deserialize the normal payload into
        E - the type to deserialize the error payload into
        Parameters:
        correlationId - the CorrelationId of the messages to receive
        subscriber - the Subscriber to invoke
        responseClass - the Class to deserialize the normal payload into
        errorClass - the Class to deserialize the error payload into
        Returns:
        a SubscriptionId to identify the Subscriber
      • subscribeRaw

        SubscriptionId subscribeRaw​(EventType eventType,
                                    Subscriber<ProcessingContext<Map<String,​Object>>> subscriber)
        Adds the Subscriber with access to the raw ProcessingContext for all messages of the EventType.
        Parameters:
        eventType - the EventType of the messages to receive
        subscriber - the Subscriber to invoke
        Returns:
        a SubscriptionId to identify the Subscriber
      • unsubscribe

        void unsubscribe​(SubscriptionId subscriptionId)
        Removes all Subscribers with the given SubscriptionId.
        Parameters:
        subscriptionId - the SubscriptionId to remove