Package com.tccc.kos.core.service.app
Class AppMessageBroker
java.lang.Object
com.tccc.kos.core.service.app.AppMessageBroker
- All Implemented Interfaces:
MessageBroker
Wrapper for the system message broker that prefixes the topics
with the application id.
- Since:
- 1.0
- Version:
- 2023-02-01
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Sends a broker message from the specified session.void
Sends a broker message to the given topic.void
Sends a broker message to the given topic with the given data.void
Sends a broker message to the given topic with the given data.void
Sends a broker message from the specified session where the body is already in parsed JSON form.void
subscribe
(Object session, String topic, MessageBrokerCallback callback) Subscribes to the specified topic.void
subscribe
(Object session, String topic, Class<?> bodyClass, MessageBrokerCallback callback) Subscribes to the specified topic.void
subscribe
(String topic, MessageBrokerCallback callback) Subscribes to the specified topic.void
subscribe
(String topic, Class<?> bodyClass, MessageBrokerCallback callback) Subscribes to the specified topic.void
unsubscribe
(Object session) Unsubscribes from all topics in the specified session.void
unsubscribe
(Object session, String topic) Unsubscribes from the specified topic.void
unsubscribe
(String topic) Unsubscribes from the specified topic.
-
Constructor Details
-
AppMessageBroker
public AppMessageBroker()
-
-
Method Details
-
subscribe
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 tocallback
- the callback to use
-
subscribe
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 tobodyClass
- the class to serialize the body to (optional)callback
- the callback to use
-
unsubscribe
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
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 interfaceMessageBroker
- Parameters:
session
- the session keytopic
- the topic to subscribe tocallback
- 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 interfaceMessageBroker
- Parameters:
session
- the session keytopic
- the topic to subscribe tobodyClass
- the class to serialize the body to (optional)callback
- the callback to use
-
unsubscribe
Description copied from interface:MessageBroker
Unsubscribes from the specified topic. The unsubscribed topic must match the topic used to subscribe.- Specified by:
unsubscribe
in interfaceMessageBroker
- Parameters:
session
- the session key (optional: no-op if null)topic
- the topic to unsubscribe form
-
unsubscribe
Description copied from interface:MessageBroker
Unsubscribes from all topics in the specified session.- Specified by:
unsubscribe
in interfaceMessageBroker
- Parameters:
session
- the session key (optional: no-op if null)
-
send
Description copied from interface:MessageBroker
Sends a broker message to the given topic.- Specified by:
send
in interfaceMessageBroker
- Parameters:
topic
- the topic to send
-
send
Description copied from interface:MessageBroker
Sends a broker message to the given topic with the given data.- Specified by:
send
in interfaceMessageBroker
- Parameters:
topic
- the topic to sendbody
- the message body (optional)
-
send
Description copied from interface:MessageBroker
Sends a broker message to the given topic with the given data.- Specified by:
send
in interfaceMessageBroker
- Parameters:
topic
- the topic to sendbody
- the message body (optional)
-
send
Description copied from interface:MessageBroker
Sends a broker message from the specified session. This session will not receive the message.- Specified by:
send
in interfaceMessageBroker
- Parameters:
session
- the sending key (optional)topic
- the topic to sendbody
- the message body (optional)jsonView
- the view to use when converting to JSON (optional)
-
sendJson
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 interfaceMessageBroker
- Parameters:
session
- the sending session key (optional)topic
- the topic to sendjsonBody
- the message body in parsed JSON (optional)
-