Class AppMessageBroker

java.lang.Object
com.tccc.kos.core.service.app.AppMessageBroker
All Implemented Interfaces:
MessageBroker

public class AppMessageBroker extends Object implements MessageBroker
Wrapper for the system message broker that prefixes the topics with the application id.
Since:
1.0
Version:
2023-02-01
  • Constructor Details

    • AppMessageBroker

      public AppMessageBroker()
  • Method Details

    • subscribe

      public void subscribe(String topic, MessageBrokerCallback callback)
      Subscribes to the specified topic. If the message has a body, then it will be accessible via jsonBody in the message data.

      The subscription will be linked to the application and will automatically be removed when the application unloads.

      Parameters:
      topic - the topic to subscribe to
      callback - the callback to use
    • subscribe

      public void subscribe(String topic, Class<?> bodyClass, MessageBrokerCallback callback)
      Subscribes to the specified topic. If a message has a body, it will be serialized to JSON. The callback has access to the JSON representation of the data in jsonBody. If a class is specified, the JSON will be deserialized at the specified class and placed in the body property of the message data.

      The subscription will be linked to the application and will automatically be removed when the application unloads.

      Parameters:
      topic - the topic to subscribe to
      bodyClass - the class to serialize the body to (optional)
      callback - the callback to use
    • unsubscribe

      public void unsubscribe(String topic)
      Unsubscribes from the specified topic. The unsubscribed topic must match the topic used to subscribe.

      This will unsubscribe an associated subscription made using the non-session subscribe calls.

      Parameters:
      topic - the topic to unsubscribe form
    • subscribe

      public void subscribe(Object session, String topic, MessageBrokerCallback callback)
      Description copied from interface: MessageBroker
      Subscribes to the specified topic. If the message has a body, then it will be accessible via jsonBody in the message data.
      Specified by:
      subscribe in interface MessageBroker
      Parameters:
      session - the session key
      topic - the topic to subscribe to
      callback - the callback to use
    • subscribe

      public void subscribe(Object session, String topic, Class<?> bodyClass, MessageBrokerCallback callback)
      Description copied from interface: MessageBroker
      Subscribes to the specified topic. If a message has a body, it will be serialized to JSON. The callback has access to the JSON representation of the data in jsonBody. If a class is specified, the JSON will be deserialized at the specified class and placed in the body property of the message data.
      Specified by:
      subscribe in interface MessageBroker
      Parameters:
      session - the session key
      topic - the topic to subscribe to
      bodyClass - the class to serialize the body to (optional)
      callback - the callback to use
    • unsubscribe

      public void unsubscribe(Object session, String topic)
      Description copied from interface: MessageBroker
      Unsubscribes from the specified topic. The unsubscribed topic must match the topic used to subscribe.
      Specified by:
      unsubscribe in interface MessageBroker
      Parameters:
      session - the session key (optional: no-op if null)
      topic - the topic to unsubscribe form
    • unsubscribe

      public void unsubscribe(Object session)
      Description copied from interface: MessageBroker
      Unsubscribes from all topics in the specified session.
      Specified by:
      unsubscribe in interface MessageBroker
      Parameters:
      session - the session key (optional: no-op if null)
    • send

      public void send(String topic)
      Description copied from interface: MessageBroker
      Sends a broker message to the given topic.
      Specified by:
      send in interface MessageBroker
      Parameters:
      topic - the topic to send
    • send

      public void send(String topic, Object body)
      Description copied from interface: MessageBroker
      Sends a broker message to the given topic with the given data.
      Specified by:
      send in interface MessageBroker
      Parameters:
      topic - the topic to send
      body - the message body (optional)
    • send

      public void send(String topic, Object body, Class<?> jsonView)
      Description copied from interface: MessageBroker
      Sends a broker message to the given topic with the given data.
      Specified by:
      send in interface MessageBroker
      Parameters:
      topic - the topic to send
      body - the message body (optional)
    • send

      public void send(Object session, String topic, Object body, Class<?> jsonView)
      Description copied from interface: MessageBroker
      Sends a broker message from the specified session. This session will not receive the message.
      Specified by:
      send in interface MessageBroker
      Parameters:
      session - the sending key (optional)
      topic - the topic to send
      body - the message body (optional)
      jsonView - the view to use when converting to JSON (optional)
    • sendJson

      public void sendJson(Object session, String topic, JsonNode jsonBody)
      Description copied from interface: MessageBroker
      Sends a broker message from the specified session where the body is already in parsed JSON form. This session will NOT receive the message.
      Specified by:
      sendJson in interface MessageBroker
      Parameters:
      session - the sending session key (optional)
      topic - the topic to send
      jsonBody - the message body in parsed JSON (optional)