Class EventMessageBridge

java.lang.Object
net.solarnetwork.node.runtime.EventMessageBridge
All Implemented Interfaces:
org.osgi.service.event.EventHandler

public class EventMessageBridge extends Object implements org.osgi.service.event.EventHandler
Bridge between OSGi EventAdmin events and a Spring Messaging.
Version:
2.1
Author:
matt
  • Field Details

    • NODE_EVENT_PREFIX

      public static final String NODE_EVENT_PREFIX
      A prefix automatically stripped from event topic values.
      See Also:
    • MESSAGE_TOPIC_PREFIX

      public static final String MESSAGE_TOPIC_PREFIX
      The prefix automatically added to every message topic value.
      See Also:
    • PUBLIC_MESSAGE_TOPIC_PREFIX

      public static final String PUBLIC_MESSAGE_TOPIC_PREFIX
      The prefix automatically added to every public message topic value.
      Since:
      1.1
      See Also:
  • Constructor Details

    • EventMessageBridge

      public EventMessageBridge(net.solarnetwork.service.OptionalService<org.springframework.messaging.simp.SimpMessageSendingOperations> messageSendingOps)
      Constructor.
      Parameters:
      messageSendingOps - the optional message sending service to use
      Throws:
      IllegalArgumentException - if messageSendingOps is null
    • EventMessageBridge

      public EventMessageBridge(net.solarnetwork.service.OptionalService<org.springframework.messaging.simp.SimpMessageSendingOperations> messageSendingOps, Executor executor)
      Constructor.
      Parameters:
      messageSendingOps - the optional message sending service to use
      executor - the optional executor to use
      Throws:
      IllegalArgumentException - if messageSendingOps is null
      Since:
      2.1
  • Method Details

    • handleEvent

      public void handleEvent(org.osgi.service.event.Event event)
      Specified by:
      handleEvent in interface org.osgi.service.event.EventHandler
    • postMessage

      protected void postMessage(String dest, Object body)
      Post a message without any headers, converting it first.

      Will silently ignore the event if no MessageSendingOperations is available.

      Parameters:
      dest - The destination to post to.
      body - The message body to post. This will be wrapped in a Result object if it is not one already.
      See Also:
    • postMessage

      protected void postMessage(String dest, Object body, Map<String,Object> headers, boolean convert)
      Post a message. Will silently ignore the event if no MessageSendingOperations is available.

      If convert is true the message will be sent via the MessageSendingOperations.convertAndSend(Object, Object, Map) method. Otherwise the MessageSendingOperations.send(Object, Message) method will be used to send the body as-is.

      Parameters:
      dest - The destination to post to.
      body - The message body to post. If convert is true then this will be wrapped in a Result object if it is not one already.
      headers - an optional set of message headers to include
      convert - true to convert the message before sending, false to send without any conversion
      Since:
      1.1
    • setTopicMapping

      public void setTopicMapping(Map<String,String> topicMapping)
      Set a mapping of event topic values to corresponding message topic values.

      The event topic values are first stripped of any NODE_EVENT_PREFIX, and the resulting value used as a key to lookup a message topic value to use from this map. The message topics can use template variables as defined in StringUtils.expandTemplateString(String, Map); all the event properties are made available to the expansion.

      Parameters:
      topicMapping - the topicMapping to set
    • setPublicTopicMapping

      public void setPublicTopicMapping(Map<String,String> publicTopicMapping)
      Set the mapping of event topic values to corresponding public message topic values.

      The same messaging handling rules as documented in setTopicMapping(Map) apply here, except that the resulting topic will have the PUBLIC_MESSAGE_TOPIC_PREFIX instead of the MESSAGE_TOPIC_PREFIX.

      Parameters:
      publicTopicMapping - the public topic mapping to set
      Since:
      1.1
      See Also: