Class MessageData

java.lang.Object
com.tccc.kos.commons.core.broker.MessageData

public class MessageData extends Object
A MessageBroker message forwarded to a subscriber, typically via the MessageBrokerCallback interface.

Messages are routed through the broker based on the topic of the message, which is a filesystem path style string. As topics are inherently hierarchical, it is possible to subscribe to a sub-topic using a wildcard to receive all child topics. It is often useful to know which subscription topic matched a particular message topic so the message contains two topic properties:

The topic property contains the topic the sender used to send the message. The subscription property contains the topic that was used during the subscribe call.

Since the broker can send messages over the kOS network, all messages are JSON serialized. When receiving a message with a body in java, the parsed body JSON will be available in the jsonBody property. If the subscribe call included a java POJO class then the body will contain an instance of the specified class, deserialized from jsonBody.

Example

 
  public class MyClass {
      @Autowired
      private MessageBroker broker;

      ...
         broker.subscribe(mySession, "/topic/goes/here", Pojo.class, (msg) -> {
            Pojo body = msg.getBody();
         }
  }
 
 
Since:
1.0
Version:
2022-09-28
See Also:
  • Constructor Details

  • Method Details

    • getSession

      public Object getSession()
    • getTopic

      public String getTopic()
    • getSubscription

      public String getSubscription()
    • getBody

      public Object getBody()
    • getJsonBody

      public JsonNode getJsonBody()
    • setSession

      public void setSession(Object session)
    • setTopic

      public void setTopic(String topic)
    • setSubscription

      public void setSubscription(String subscription)
    • setBody

      public void setBody(Object body)
    • setJsonBody

      public void setJsonBody(JsonNode jsonBody)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object