public final class ThirdPartyContext extends java.lang.Object implements Closeable
ThirdPartyContext
helps to represent an external system as a Bounded Context. Events
which occur in the external system are converted into domain events of the user's
Bounded Contexts and dispatched via IntegrationBroker
.
ThirdPartyContext
sends a request for external messages to
other contexts. The ThirdPartyContext
never consumes external messages itself,
but requires the other Bounded Contexts to send their requests, so that the publishing
channels are open. Depending of the implementation of
transport
, creating
a ThirdPartyContext
may be an expensive operation. Thus, it is recommended that
the instances of this class are reused and closed when they are
no longer needed.Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this Context and clean up underlying resources.
|
void |
emittedEvent(io.spine.base.EventMessage eventMessage,
io.spine.core.ActorContext actorContext)
Emits an event from the third-party system.
|
void |
emittedEvent(io.spine.base.EventMessage eventMessage,
io.spine.core.UserId userId)
Emits an event from the third-party system.
|
boolean |
isOpen()
Tells if the object is still open.
|
static ThirdPartyContext |
multitenant(java.lang.String name)
Creates a new multitenant instance of
ThirdPartyContext with the given name. |
static ThirdPartyContext |
singleTenant(java.lang.String name)
Creates a new single-tenant instance of
ThirdPartyContext with the given name. |
public static ThirdPartyContext singleTenant(java.lang.String name)
ThirdPartyContext
with the given name.name
- name of the Bounded Context representing a part of a third-party systempublic static ThirdPartyContext multitenant(java.lang.String name)
ThirdPartyContext
with the given name.name
- name of the Bounded Context representing a part of a third-party systempublic void emittedEvent(io.spine.base.EventMessage eventMessage, io.spine.core.ActorContext actorContext)
If the event is required by another Context, posts the event into
the IntegrationBroker
of the respective Context. Does nothing if the event is not
required by any Context.
The caller is required to supply the tenant ID via the ActorContext.tenant_id
if
this Context is multitenant.
eventMessage
- the eventactorContext
- the info about the actor, a user or a software component, who emits the eventpublic void emittedEvent(io.spine.base.EventMessage eventMessage, io.spine.core.UserId userId)
If the event is required by another Context, posts the event into
the IntegrationBroker
of the respective Context. Does nothing if the event is not
required by any Context.
This overload may only be used for single-tenant third-party contexts. If this Context is multitenant, this method throws an exception.
eventMessage
- the eventuserId
- the ID of the actor, a user or a software component, who emits the eventpublic void close() throws java.lang.Exception
Attempts of emitting an event from a closed Context result in an exception.
close
in interface java.lang.AutoCloseable
java.lang.Exception
- if the underlying BoundedContext
fails to close