Class AbstractMessagingService

java.lang.Object
com.sap.cds.services.ServiceDelegator
com.sap.cds.services.messaging.service.AbstractMessagingService
All Implemented Interfaces:
MessagingService, Service

public abstract class AbstractMessagingService extends ServiceDelegator implements MessagingService
Implementation of the MessagingService interface.
  • Field Details

  • Constructor Details

  • 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

      public void emit(EventContext context)
      Specified by:
      emit in interface Service
      Overrides:
      emit in class ServiceDelegator
    • isCloudEventsFormat

      protected boolean isCloudEventsFormat()
    • emit

      public void emit(String topic, String message)
      Specified by:
      emit in interface MessagingService
    • emit

      public void emit(String topic, Map<String,Object> dataMap)
      Specified by:
      emit in interface MessagingService
    • emit

      public void emit(String topic, Map<String,Object> dataMap, Map<String,Object> headersMap)
      Specified by:
      emit in interface MessagingService
    • validateEventContext

      @HandlerOrder(-2147483648) protected void validateEventContext(TopicMessageEventContext context)
    • cloudEventsFormatter

      @HandlerOrder(11000) protected void cloudEventsFormatter(TopicMessageEventContext context)
    • sendMessageEvent

      @HandlerOrder(-9900) protected void sendMessageEvent(TopicMessageEventContext context)
    • defaultErrorHandler

      @HandlerOrder(11000) protected void defaultErrorHandler(MessagingErrorEventContext context)
    • on

      public void on(String[] events, String[] entities, int order, Handler handler)
      Specified by:
      on in interface Service
      Overrides:
      on in class ServiceDelegator
    • toFullyQualifiedQueueName

      protected String toFullyQualifiedQueueName(MessageQueue queue)
      Translates the queue name corresponding the broker queue name specification.
      Parameters:
      queue - queue specification
      Returns:
      broker environment specific queue name
    • toFullyQualifiedTopicName

      protected String toFullyQualifiedTopicName(String event, boolean inbound)
      Translates the given event definition to the broker environment specific name.
      Parameters:
      event - event definition
      inbound - determines whether topic is used for subscription
      Returns:
      the list of topic names corresponding the broker environment.
    • getTopicMatcher

      protected BiPredicate<MessageTopic,String> 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

      protected abstract void removeQueue(String name) throws IOException
      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

      protected abstract void createQueue(String name, Map<String,String> properties) throws IOException
      Request the broker for creating a queue with the specified queue name.
      Parameters:
      name - queue name
      properties - queue configuration properties
      Throws:
      IOException - In case an error occurs while creating the queue
    • createQueueSubscription

      protected abstract void createQueueSubscription(String queue, String topic) throws IOException
      Requests the broker for creating a queue topic subscription. The method returnstrue only when the queue topic subscription was successfully created or already available. Otherwise false is returned.
      Parameters:
      queue - the queue name
      topic - 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 the MessagingBrokerQueueListener implementation to the specified queue of the message broker.
      Parameters:
      queue - the queue name
      listener - implementation of the MessagingBrokerQueueListener interface
      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 topic
      topicMessageEventContext - the TopicMessageEventContext of the message