public interface MessageChannelKeyResolver
MessageChannel
s can be configured with a channel key that is used to resolve
the message key on which a message is sent through the channel. In most cases a message
key can be thought of as being synonymous with a topic or queue (depending on the message
bus binding), SMA uses the term message key as more general abstraction to cover a broader arrange of
messaging provider types. This abstraction is an important one in SMA, as it allows the channel's
physical destination to be configured rather than hard coded into an application which in turn
allows changing of the destination or messaging provider at runtime without application code changes.
A MessageChannel
may be configured with a dynamic key, a key that has variable components
that are resolved dynamically at run time based on the contents of:
As an example, a channel key of 'ORDERS/${salesRegion:US}/${productId}/Purchases'
is
a dynamic key having variable key components of 'salesRegion' and '${productId}', with 'salesRegion'
specifying a default value of 'US' in cases where it is unspecified. When a message
is sent over a MessageChannel
, all variable key components have to be resolved
or an SmaException
will be thrown.
A MessageChannelKeyResolver
handles this dynamic key resolution by building the
key on which the message is sent.
Most application working with SMA won't use the MessageChannelKeyResolver
directly,
but will instead call MessageChannel.sendMessage(MessageView, RawKeyResolutionTable, com.neeve.sma.MessageBusBinding.FlushContext, int)
which will invoke the MessageChannel
's MessageChannelKeyResolver
automatically when
the MessageView
's key has not been set.
Applications that resolve the channel key prior to calling send on the channel may use a MessageChannelKeyResolver
directly and set the resolved key on the MessageView
or, preferably, call MessageView#resolveMessageKeyWith(MessageChannelKeyResolver, RawKeyResolutionTable)
instead which can resolve a MessageKey directly into backing buffer for the message without making an intermediate copy.
Modifier and Type | Method and Description |
---|---|
Properties |
getKeyResolutionTable()
Gets the preconfigured properties based key resolution table associated with this resolver.
|
MessageChannel.RawKeyResolutionTable |
getRawKeyResolutionTable()
Gets the preconfigured 'raw' key resolution table associated with this resolver.
|
String |
resolveMessageKey(MessageView view,
Properties callerSuppliedKRT)
Resolve a message's key using a channel key.
|
XString |
resolveMessageKey(XString target,
MessageView view,
MessageChannel.RawKeyResolutionTable callerSuppliedKRT)
Resolve a message's key using the channel key, into the provided
XString . |
Properties getKeyResolutionTable()
When non null, it is illegal to call #resolveMessageKey(XString, MessageView, RawKeyResolutionTable)
.
MessageChannel.RawKeyResolutionTable getRawKeyResolutionTable()
When non null, it is illegal to call resolveMessageKey(MessageView, Properties)
.
String resolveMessageKey(MessageView view, Properties callerSuppliedKRT) throws SmaException
This method is resolves a message's key by substituting variable key
elements in the associated channel key. Unless otherwise specified by a particular
channel key implementation, a channel key consists of static and variable portions
with the variable portions consisting identified in the form of ${propName[:defaultValue]}.
For example, a channel key of 'ORDERS/${salesRegion:US}/${productId}/Purchases' is interpreted
as having variable key components of 'salesRegion' and '${productId}', with 'salesRegion'
specifying a default value of 'US' in cases where it is unspecified. When a message
is sent over a MessageChannel
, all variable key components have to be resolved
or an SmaException
will be thrown. Variable key components are resolved from the
following sources in this order:
view
- The message view whose key is to be resolved.callerSuppliedKRT
- A table to be used during the key resolution process.SmaException
- If there is an error in key resolution.IllegalArgumentException
- if the resolver is configured with a MessageChannel.RawKeyResolutionTable
XString resolveMessageKey(XString target, MessageView view, MessageChannel.RawKeyResolutionTable callerSuppliedKRT) throws SmaException
XString
. This
method produces the same key as resolveMessageKey(MessageView, Properties)
, but
does not produce garbage if the provided target XString
is mutable.
This method is resolves a message's key by substituting variable key
elements in the channel's key. Unless otherwise specified by the a particular
channel key implementation, a channel key consists of static and variable portions
with the variable portions consisting identified in the form of ${propName[::defaultValue]}.
For example a channel key of 'ORDERS/${salesRegion::US}/${productId}/Purchases' is interpreted
as having variable key components of 'salesRegion' and '${productId}', with 'salesRegion'
specifying a default value of 'US' in cases where it is unspecified. When a message
is sent over a MessageChannel
, all variable key components have to be resolved
or an SmaException
will be thrown. Variable key components are resolved from the
following sources in this order:
target
- The message view whose key is to be resolved.view
- The message view whose key is to be resolved.callerSuppliedKRT
- A table to be used during the key resolution process.XString
containing the resolved key. If not null the returned
XString
will be the same as that passed into the method unless the passed
in XString
is immutable in which case a new XString
will be
allocated.SmaException
- If there is an error in key resolution.IllegalArgumentException
- if the resolver is configured with a Properties
based KRT.XString
or the modifying
the values in the keyResolutionTable, or the message contents.Copyright © 2019 Neeve Research, LLC. All Rights Reserved.