Interface SerializedMessageBus
-
- All Known Implementing Classes:
SerializedMessageBusImpl
public interface SerializedMessageBusASerializedMessageBusenhances a typicalMessageBuswith 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 aMessageFunctionby providing functions, that wait on a matching response.- See Also:
- EventMaid Documentation
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static SerializedMessageBusaSerializedMessageBus(MessageBus messageBus, Serializer requestSerializer, Deserializer responseDeserializer)Factory method to create a newSerializedMessageBusfrom the normalMessageBus, aDeserializerand aSerializer.PayloadAndErrorPayload<Object,Object>invokeAndWait(EventType eventType, Object data)Sends the data and waits for a matching response or an exception.PayloadAndErrorPayload<Object,Object>invokeAndWait(EventType eventType, Object data, long timeout, TimeUnit unit)Sends the data and waits for a matching response, an exception or the timeout to expire.<P,E>
PayloadAndErrorPayload<P,E>invokeAndWaitDeserialized(EventType eventType, Object data, Class<P> responseClass, Class<E> errorPayloadClass)Serializes and sends the data on theMessageBus.<P,E>
PayloadAndErrorPayload<P,E>invokeAndWaitDeserialized(EventType eventType, Object data, Class<P> responseClass, Class<E> errorPayloadClass, long timeout, TimeUnit unit)Serializes and sends the data on theMessageBus.PayloadAndErrorPayload<Object,Object>invokeAndWaitSerializedOnly(EventType eventType, Object data)Serializes the data before sending it and waiting for a matching response or an exception.PayloadAndErrorPayload<Object,Object>invokeAndWaitSerializedOnly(EventType eventType, Object data, long timeout, TimeUnit unit)Serializes the data before sending it and waiting for a matching response, an exception or the expiration of the timeout.MessageIdsend(EventType eventType, Object data)Sends the given data in form of aMapon theMessageBuswith theEventType.MessageIdsend(EventType eventType, Object data, CorrelationId correlationId)Sends the given data in form of aMapon theMessageBuswith theEventTypeandCorrelationIdset.MessageIdsend(EventType eventType, Object data, Object errorData)Sends the given data and error data both in form of aMapon theMessageBuswith theEventType.MessageIdsend(EventType eventType, Object data, Object errorData, CorrelationId correlationId)Sends the given data and error data both in form of aMapon theMessageBuswith theEventTypeandCorrelationId.MessageIdserializeAndSend(EventType eventType, Object data)MessageIdserializeAndSend(EventType eventType, Object data, CorrelationId correlationId)Serializes the data to aMapand then sends it with theEventTypeandCorrelationIdon theMessageBus.MessageIdserializeAndSend(EventType eventType, Object data, Object errorData)Serializes the data and error data to aMapand then sends both with theEventTypeon theMessageBus.MessageIdserializeAndSend(EventType eventType, Object data, Object errorData, CorrelationId correlationId)Serializes the data and error data to aMapand then sends both with theEventTypeandCorrelationIdon theMessageBus.SubscriptionIdsubscribe(CorrelationId correlationId, Subscriber<PayloadAndErrorPayload<Map<String,Object>,Map<String,Object>>> subscriber)Adds the givenSubscriberfor all not deserialized messages of the givenCorrelationId.SubscriptionIdsubscribe(EventType eventType, Subscriber<PayloadAndErrorPayload<Map<String,Object>,Map<String,Object>>> subscriber)Adds the givenSubscriberfor all not deserialized messages of the givenEventType.<P,E>
SubscriptionIdsubscribeDeserialized(CorrelationId correlationId, Subscriber<PayloadAndErrorPayload<P,E>> subscriber, Class<P> responseClass, Class<E> errorClass)Adds the givenSubscriberfor all messages of the givenEventType.<P,E>
SubscriptionIdsubscribeDeserialized(EventType eventType, Subscriber<PayloadAndErrorPayload<P,E>> subscriber, Class<P> responseClass, Class<E> errorClass)Adds the givenSubscriberfor all messages of the givenEventType.SubscriptionIdsubscribeRaw(EventType eventType, Subscriber<ProcessingContext<Map<String,Object>>> subscriber)Adds theSubscriberwith access to the rawProcessingContextfor all messages of theEventType.voidunsubscribe(SubscriptionId subscriptionId)Removes allSubscriberswith the givenSubscriptionId.
-
-
-
Method Detail
-
aSerializedMessageBus
static SerializedMessageBus aSerializedMessageBus(MessageBus messageBus, Serializer requestSerializer, Deserializer responseDeserializer)
Factory method to create a newSerializedMessageBusfrom the normalMessageBus, aDeserializerand aSerializer.- Parameters:
messageBus- theMessageBusto wraprequestSerializer- theSerializerto serialize objects being sent on the busresponseDeserializer- theDeserializerto 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 aMapon theMessageBuswith theEventType.- Parameters:
eventType- theEventTypeto relate the message todata- the data to send- Returns:
- a unique
MessageIdfor the message
-
send
MessageId send(EventType eventType, Object data, CorrelationId correlationId)
Sends the given data in form of aMapon theMessageBuswith theEventTypeandCorrelationIdset.- Parameters:
eventType- theEventTypeto relate the message todata- the data to sendcorrelationId- theCorrelationIdrelating to a previousMessageId- Returns:
- a unique
MessageIdfor the message
-
send
MessageId send(EventType eventType, Object data, Object errorData)
Sends the given data and error data both in form of aMapon theMessageBuswith theEventType.- Parameters:
eventType- theEventTypeto relate the message todata- the data to senderrorData- the error data to send- Returns:
- a unique
MessageIdfor the message
-
send
MessageId send(EventType eventType, Object data, Object errorData, CorrelationId correlationId)
Sends the given data and error data both in form of aMapon theMessageBuswith theEventTypeandCorrelationId.- Parameters:
eventType- theEventTypeto relate the message todata- the data to senderrorData- the error data to sendcorrelationId- theCorrelationIdrelating to a previousMessageId- Returns:
- a unique
MessageIdfor the message
-
serializeAndSend
MessageId serializeAndSend(EventType eventType, Object data)
- Parameters:
eventType- theEventTypeto relate the message todata- the data to serialize and send- Returns:
- a unique
MessageIdfor the message
-
serializeAndSend
MessageId serializeAndSend(EventType eventType, Object data, CorrelationId correlationId)
Serializes the data to aMapand then sends it with theEventTypeandCorrelationIdon theMessageBus.- Parameters:
eventType- theEventTypeto relate the message todata- the data to serialize and sendcorrelationId- theCorrelationIdrelating to a previousMessageId- Returns:
- a unique
MessageIdfor the message
-
serializeAndSend
MessageId serializeAndSend(EventType eventType, Object data, Object errorData)
Serializes the data and error data to aMapand then sends both with theEventTypeon theMessageBus.- Parameters:
eventType- theEventTypeto relate the message todata- the data to serialize and senderrorData- the error data to send- Returns:
- a unique
MessageIdfor the message
-
serializeAndSend
MessageId serializeAndSend(EventType eventType, Object data, Object errorData, CorrelationId correlationId)
Serializes the data and error data to aMapand then sends both with theEventTypeandCorrelationIdon theMessageBus.- Parameters:
eventType- theEventTypeto relate the message todata- the data to serialize and senderrorData- the error data to sendcorrelationId- theCorrelationIdrelating to a previousMessageId- Returns:
- a unique
MessageIdfor the message
-
invokeAndWait
PayloadAndErrorPayload<Object,Object> invokeAndWait(EventType eventType, Object data) throws InterruptedException, ExecutionException
Sends the data and waits for a matching response or an exception.- Parameters:
eventType- theEventTypeto relate the message todata- the error data to send- Returns:
- the not deserialized normal and error payload
- Throws:
InterruptedException- if the waitingThreadis interruptedExecutionException- if the message or response caused an exception
-
invokeAndWait
PayloadAndErrorPayload<Object,Object> invokeAndWait(EventType eventType, Object data, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
Sends the data and waits for a matching response, an exception or the timeout to expire.- Parameters:
eventType- theEventTypeto relate the message todata- the error data to sendtimeout- the timeout intervalunit- the unit to measure the interval in- Returns:
- the not deserialized normal and error payload
- Throws:
InterruptedException- if the waitingThreadis interruptedExecutionException- if the message or response caused an exceptionTimeoutException- if the timeout expired
-
invokeAndWaitSerializedOnly
PayloadAndErrorPayload<Object,Object> invokeAndWaitSerializedOnly(EventType eventType, Object data) throws InterruptedException, ExecutionException
Serializes the data before sending it and waiting for a matching response or an exception.- Parameters:
eventType- theEventTypeto relate the message todata- the error data to send- Returns:
- the not deserialized normal and error payload
- Throws:
InterruptedException- if the waitingThreadis interruptedExecutionException- if the message or response caused an exception
-
invokeAndWaitSerializedOnly
PayloadAndErrorPayload<Object,Object> invokeAndWaitSerializedOnly(EventType eventType, Object data, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
Serializes the data before sending it and waiting for a matching response, an exception or the expiration of the timeout.- Parameters:
eventType- theEventTypeto relate the message todata- the error data to sendtimeout- the timeout intervalunit- the unit to measure the interval in- Returns:
- the not deserialized normal and error payload
- Throws:
InterruptedException- if the waitingThreadis interruptedExecutionException- if the message or response caused an exceptionTimeoutException- if the timeout expired
-
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 theMessageBus. 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 toE- the type to deserialize the error response to- Parameters:
eventType- theEventTypeto relate the message todata- the error data to sendresponseClass- the class to deserialize the normal response toerrorPayloadClass- the class to deserialize the error response to- Returns:
- the deserialized normal and error payload
- Throws:
InterruptedException- if the waitingThreadis interruptedExecutionException- 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 theMessageBus. 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 toE- the type to deserialize the error response to- Parameters:
eventType- theEventTypeto relate the message todata- the error data to sendresponseClass- the class to deserialize the normal response toerrorPayloadClass- the class to deserialize the error response totimeout- the timeout intervalunit- the unit to measure the interval in- Returns:
- the deserialized normal and error payload
- Throws:
InterruptedException- if the waitingThreadis interruptedExecutionException- if the message or response caused an exceptionTimeoutException- if the timeout expired
-
subscribe
SubscriptionId subscribe(EventType eventType, Subscriber<PayloadAndErrorPayload<Map<String,Object>,Map<String,Object>>> subscriber)
Adds the givenSubscriberfor all not deserialized messages of the givenEventType.- Parameters:
eventType- theEventTypeof the messages to receivesubscriber- theSubscriberto invoke- Returns:
- a
SubscriptionIdto identify theSubscriber
-
subscribe
SubscriptionId subscribe(CorrelationId correlationId, Subscriber<PayloadAndErrorPayload<Map<String,Object>,Map<String,Object>>> subscriber)
Adds the givenSubscriberfor all not deserialized messages of the givenCorrelationId.- Parameters:
correlationId- theCorrelationIdof the messages to receivesubscriber- theSubscriberto invoke- Returns:
- a
SubscriptionIdto identify theSubscriber
-
subscribeDeserialized
<P,E> SubscriptionId subscribeDeserialized(EventType eventType, Subscriber<PayloadAndErrorPayload<P,E>> subscriber, Class<P> responseClass, Class<E> errorClass)
Adds the givenSubscriberfor all messages of the givenEventType. The normal and error payload are deserialized into the to givenClasses.- Type Parameters:
P- the type to deserialize the normal payload intoE- the type to deserialize the error payload into- Parameters:
eventType- theEventTypeof the messages to receivesubscriber- theSubscriberto invokeresponseClass- theClassto deserialize the normal payload intoerrorClass- theClassto deserialize the error payload into- Returns:
- a
SubscriptionIdto identify theSubscriber
-
subscribeDeserialized
<P,E> SubscriptionId subscribeDeserialized(CorrelationId correlationId, Subscriber<PayloadAndErrorPayload<P,E>> subscriber, Class<P> responseClass, Class<E> errorClass)
Adds the givenSubscriberfor all messages of the givenEventType. The normal and error payload are deserialized into the to givenClasses.- Type Parameters:
P- the type to deserialize the normal payload intoE- the type to deserialize the error payload into- Parameters:
correlationId- theCorrelationIdof the messages to receivesubscriber- theSubscriberto invokeresponseClass- theClassto deserialize the normal payload intoerrorClass- theClassto deserialize the error payload into- Returns:
- a
SubscriptionIdto identify theSubscriber
-
subscribeRaw
SubscriptionId subscribeRaw(EventType eventType, Subscriber<ProcessingContext<Map<String,Object>>> subscriber)
Adds theSubscriberwith access to the rawProcessingContextfor all messages of theEventType.- Parameters:
eventType- theEventTypeof the messages to receivesubscriber- theSubscriberto invoke- Returns:
- a
SubscriptionIdto identify theSubscriber
-
unsubscribe
void unsubscribe(SubscriptionId subscriptionId)
Removes allSubscriberswith the givenSubscriptionId.- Parameters:
subscriptionId- theSubscriptionIdto remove
-
-