The Liferay Community has been integral to our journey.
Join us as we build its future, together.
Inter Gadget Communication with PubSub:
Like Inter Portlet Communication(IPC), communication between two gadgets or between gadget and portlet is also very important. OpenSocial provide mechanism to establish communication between gadget to gadget or gadget to portlet or vice versa using pubsub.
Pubsub works like event fire/listen in AUI. There is one publisher gadget which publishes to the topic and There may be multiple consumer gadgets which has subscribed the topic. Publishers don’t send messages to subscribers directly because publisher have no knowledge about subscribers. Publisher broadcast the messages over a channel(topic). Subscriber need to subscribe channels(topics) to receive message.
Publisher Gadget
To publish a message publisher gadget need to add topic details in Require tag like :
Here com.example.opensocial.testgadget is topic name which subscribers need to subscribe to receive message. And publishing can be done by the Javascript method call :
Here first parameter is topic name and second is a variable which need to publish.
Subscriber Gadget
To receive a message from publisher, receiver gadget need to subscribe topic. Following the example to subscribe a topic:
Here first parameter in subscribe function is topic name which need to subscribe and the second parameter is call back function name that will be called when a message is published by publisher gadget. The published message can be used in callback function:
You can find publisher / subscriber gadget example on @dejuknow's github.


