Class AbstractMessagingService
java.lang.Object
com.sap.cds.services.ServiceDelegator
com.sap.cds.services.messaging.service.AbstractMessagingService
- All Implemented Interfaces:
MessagingService,Service
Implementation of the
MessagingService interface.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected final booleanprotected static final Stringprotected final MessageQueueprotected final CdsRuntimeprotected final CdsProperties.Messaging.MessagingServiceConfigFields inherited from interface com.sap.cds.services.messaging.MessagingService
COMPOSITE_NAME, EVENT_MESSAGING_ERROR -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractMessagingService(CdsProperties.Messaging.MessagingServiceConfig serviceConfig, CdsRuntime runtime) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected booleanPerforms the initialization of the messaging service, by initializing the queues and registering the topic subscriptions.protected abstract voidcreateQueue(String name, Map<String, String> properties) Request the broker for creating a queue with the specified queue name.protected abstract voidcreateQueueSubscription(String queue, String topic) Requests the broker for creating a queue topic subscription.protected voidvoidemit(EventContext context) voidvoidvoidprotected abstract voidemitTopicMessage(String topic, TopicMessageEventContext topicMessageEventContext) Performs the message emit on the messaging broker.protected BiPredicate<MessageTopic,String> The topic matcher is used when the broker subscribes to a topic pattern.voidinit()Performs the initialization of the messaging service, by initializing the queues and registering the topic subscriptions.protected booleanvoidprotected abstract voidregisterQueueListener(String queue, MessagingBrokerQueueListener listener) Registers theMessagingBrokerQueueListenerimplementation to the specified queue of the message broker.protected abstract voidremoveQueue(String name) Request the broker for queue deletion with all its subscriptions.protected voidsendMessageEvent(TopicMessageEventContext context) voidstop()Used to stop the resources allocated by the messaging service, e.g.protected StringTranslates the queue name corresponding the broker queue name specification.protected StringtoFullyQualifiedTopicName(String event, boolean inbound) Translates the given event definition to the broker environment specific name.protected voidMethods inherited from class com.sap.cds.services.ServiceDelegator
after, before, getDelegatedService, getName
-
Field Details
-
FORMAT_CLOUDEVENTS
- See Also:
-
CONTEXT_PARAMETERS_KEY
- See Also:
-
serviceConfig
-
runtime
-
queue
-
forceListening
protected final boolean forceListening
-
-
Constructor Details
-
AbstractMessagingService
protected AbstractMessagingService(CdsProperties.Messaging.MessagingServiceConfig serviceConfig, CdsRuntime runtime)
-
-
Method Details
-
init
public void init()Performs the initialization of the messaging service, by initializing the queues and registering the topic subscriptions. -
stop
public void stop()Used to stop the resources allocated by the messaging service, e.g. AMQP connections -
createOrUpdateQueuesAndSubscriptions
protected boolean createOrUpdateQueuesAndSubscriptions()Performs the initialization of the messaging service, by initializing the queues and registering the topic subscriptions.- Returns:
- true, if the initialization created queues and/or subscriptions
-
emit
- Specified by:
emitin interfaceService- Overrides:
emitin classServiceDelegator
-
isCloudEventsFormat
protected boolean isCloudEventsFormat() -
emit
- Specified by:
emitin interfaceMessagingService
-
emit
- Specified by:
emitin interfaceMessagingService
-
emit
- Specified by:
emitin interfaceMessagingService
-
validateEventContext
-
cloudEventsFormatter
-
sendMessageEvent
-
defaultErrorHandler
-
on
- Specified by:
onin interfaceService- Overrides:
onin classServiceDelegator
-
toFullyQualifiedQueueName
Translates the queue name corresponding the broker queue name specification.- Parameters:
queue- queue specification- Returns:
- broker environment specific queue name
-
toFullyQualifiedTopicName
Translates the given event definition to the broker environment specific name.- Parameters:
event- event definitioninbound- determines whether topic is used for subscription- Returns:
- the list of topic names corresponding the broker environment.
-
getTopicMatcher
The topic matcher is used when the broker subscribes to a topic pattern. In this case the implementation is needed to match the incoming message topic to the CAP registered topic pattern (e.g "+/+/+/myTopic" to "my/client/namespace/myTopic").- Returns:
- the topic matcher
-
removeQueue
Request the broker for queue deletion with all its subscriptions.- Parameters:
name- queue name- Throws:
IOException- In case an error occurs while creating the queue
-
createQueue
Request the broker for creating a queue with the specified queue name.- Parameters:
name- queue nameproperties- queue configuration properties- Throws:
IOException- In case an error occurs while creating the queue
-
createQueueSubscription
Requests the broker for creating a queue topic subscription. The method returnstrueonly when the queue topic subscription was successfully created or already available. Otherwisefalseis returned.- Parameters:
queue- the queue nametopic- the topic the queue should subscribe to- Throws:
IOException- In case an error occurs during the subscription
-
registerQueueListener
protected abstract void registerQueueListener(String queue, MessagingBrokerQueueListener listener) throws IOException Registers theMessagingBrokerQueueListenerimplementation to the specified queue of the message broker.- Parameters:
queue- the queue namelistener- implementation of theMessagingBrokerQueueListenerinterface- Throws:
IOException- In case when any errors occurs while registering the listener to the broker
-
emitTopicMessage
protected abstract void emitTopicMessage(String topic, TopicMessageEventContext topicMessageEventContext) Performs the message emit on the messaging broker.- Parameters:
topic- the message topictopicMessageEventContext- the TopicMessageEventContext of the message
-