Class MessageData
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 Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionboolean
getBody()
getTopic()
int
hashCode()
void
void
setJsonBody
(JsonNode jsonBody) void
setSession
(Object session) void
setSubscription
(String subscription) void
toString()
-
Constructor Details
-
MessageData
public MessageData() -
MessageData
-
-
Method Details