Class EventMessageBridge
- All Implemented Interfaces:
org.osgi.service.event.EventHandler
- Version:
- 2.0
- Author:
- matt
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEventMessageBridge(net.solarnetwork.service.OptionalService<org.springframework.messaging.simp.SimpMessageSendingOperations> messageSendingOps) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidhandleEvent(org.osgi.service.event.Event event) protected voidpostMessage(String dest, Object body) Post a message without any headers, converting it first.protected voidPost a message.voidsetPublicTopicMapping(Map<String, String> publicTopicMapping) Set the mapping of event topic values to corresponding public message topic values.voidsetTopicMapping(Map<String, String> topicMapping) Set a mapping of event topic values to corresponding message topic values.
-
Field Details
-
NODE_EVENT_PREFIX
A prefix automatically stripped from event topic values.- See Also:
-
MESSAGE_TOPIC_PREFIX
The prefix automatically added to every message topic value.- See Also:
-
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
-
-
Method Details
-
handleEvent
public void handleEvent(org.osgi.service.event.Event event) - Specified by:
handleEventin interfaceorg.osgi.service.event.EventHandler
-
postMessage
Post a message without any headers, converting it first.Will silently ignore the event if no
MessageSendingOperationsis available.- Parameters:
dest- The destination to post to.body- The message body to post. This will be wrapped in aResultobject if it is not one already.- See Also:
-
postMessage
Post a message. Will silently ignore the event if noMessageSendingOperationsis available.If
convertis true the message will be sent via theMessageSendingOperations.convertAndSend(Object, Object, Map)method. Otherwise theMessageSendingOperations.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. Ifconvertis true then this will be wrapped in aResultobject if it is not one already.headers- an optional set of message headers to includeconvert- true to convert the message before sending, false to send without any conversion- Since:
- 1.1
-
setTopicMapping
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 inStringUtils.expandTemplateString(String, Map); all the event properties are made available to the expansion.- Parameters:
topicMapping- the topicMapping to set
-
setPublicTopicMapping
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 thePUBLIC_MESSAGE_TOPIC_PREFIXinstead of theMESSAGE_TOPIC_PREFIX.- Parameters:
publicTopicMapping- the public topic mapping to set- Since:
- 1.1
- See Also:
-