Exchange
abstraction over Publish-Subscribe messaging for exchanges or topics. This is a means to publish messages to exchanges/topics inside or outside your current application/service, and to subscribe to such messages. The Exchange
provides translators from internal to external message types, and from external to internal message types.Exchange
itself is the primary protocol. It defines a message exchange, such as a queue or topic, through which any number of related ExchangeSender
, ExchangeReceiver
, and ExchangeAdapter
components are registered, and messages are sent. The protocol is defined as follows.Exchange
and any underlying resources. Given that the Exchange
is backed by some middleware messaging mechanism, and connections and other allocated resources to the mechanism are closed.T
type is a parameter that determines the dynamic cast to the runtime type.T
type is a parameter that determines the dynamic cast to the runtime type.Exchange
as a String
.Covey
with the Exchange
. A Covey
is a set of Exchange
components used to send, receive, and translate messages. The Covey
is explained in a below subsection.local
message to the Exchange
after first adapting it to an Exchange
-compatible message. Any given message has three forms:ConnectionSettings
is a configuration for making a connection to the underlying messaging mechanism, including information for the host, port, virtual host, and user.Covey
as a set of Exchange
components used for translating, sending, and receiving messages. A given Exchange
will have one Covey
for each local message type, either as a sender or a receiver of that message type.adapter
is an ExchangeAdapter
that is capable of adapting messages to their three forms, Local, External, and Exchange.receiver
is an ExchangeReceiver
of messages of local type, meaning that the ExchangeAdapter
has already adapted the incoming message to the local type.sender
is an ExchangeSender
of messages of exchange type through the Exchange
, meaning that the ExchangeAdapter
has already adapted the local message to an outgoing type.Class
instances is the type of a message form: localClass
, externalClass
, exchangeClass
.Queue
is just a specialized Exchange
. It is expected that a Queue
is not a fanout type but one that is point-to-point. Being point-to-point does not prevent the receiver end from enlisting multipleQueue
competing consumers. The Queue
protocol is identical to the Exchange
.Exchange
or Queue
. E
exchange typed message through the underlying exchange or queue, meaning that the ExchangeAdapter
has already adapted the local message to an outgoing type.Exchange#send()
does not actually send the message. Instead it dispatches the local message through the Forwarder
for translation to the exchange type, and then the Forwarder
dispatches the message to the ExchangeSender
.ExchangeSender
and exchange messages through the ExchangeReceiver
. It is the Forwarder
that holds the Covey
instances in behalf of the Exchange
or Queue
, and thus manages translation from local to exchange types and from exchange to local types.Exchange
, which may be implemented for each unique message type. The message type received has already been mapped and adapted from the exchange-typed message, and this is in the form of a local message.L
local typed message from the Exchange
. The message is of local type L
having already been mapped and adapted from the exchange-typed message.L
to exchange messages of type EX
that hold external type E
. This may involve mapping, in which case the underlying implementation must arrange for an ExchangeMapper
to be registered and used. Note that the L and E types may be different between ExchangeAdapter
and ExchangeMapper
.L
, E
, and EX
are the local form, the external form, and the exchange form types, respectively. The operations of this protocol work as follows.L
typed local message from the exchangeMessage
of type EX
.EX
typed exchange message from the localMessage
of type L
.exchangeMessage
. This is used by the Forwarder
to find the Covey
used for the type of exchangeMessage
.L
and E
are the local form type and the external form type, respectively. The mapper operations are used as follows.Exchange
. It provides a very simple usage example based on the RabbitMQ implementation.Exchange
.settings()
is defined as:localhost
and uses the default port by passing the value of UndefinedPort
, which is -1
. The virtualHost
is "/"
and the username
and password
are both "guest"
. Exchange
is open we can register a Covey
to handle a given set of message types.String
. The exchange message type is Message
, which is a specialized RabbitMQ type.Message
holds a byte[] payload
and an instance of MessageParameters
as metadata. The Message
may be constructed using a byte[]
or a String
, which is converted to a byte[]
, along with MessageParameters
.Covey
registration on the Exchange
. The MessageSender
is a predefined implementation of ExchangeSender
specifically for RabbitMQ. You instantiate the MessageSender
with the Exchange
's connection.TextMessageReceiver
and TextExchangeAdapter
are specifically for String
messages. The TextMessageReceiver
is implemented as follows.receive()
method will apply the message as appropriate for your service/application. The following is the TextExchangeAdapter
.Message
received from the Exchange
. To adapt from an Exchange
-received Message
to a String
, the adapter calls on the TextExchangeMapper
. To get a String
from the byte[] payload
, the adapter uses Message#payloadAsText()
. localMessage
to a Message
for the Exchange
requires constructing with the localMessage
that is converted into a byte[]
, and providing a MessageParameters
instance indicating that the Message
must be sent as durable.String
to String
, has almost no heavy-lifting functionality. Note that a new String
is created from both local and external String
messages to ensure the instances are different.equals()
, hashCode()
, and toString()
, but are excluded here for clarity.String
, int
, and float
types, while the external types hold only String
attribute types. Also the attribute names are different. This justifies the need for an adapter and mapper for each local to external type. First are the adapter and mapper for LocalType1
and ExternalType1
.LocalType2
and ExternalType2
.Covey
and registered with the Exchange
or Queue
.