1. under META-INF add message-spring.xml file .
<?xml version="1.0"?>
<beans
default-destroy-method="destroy"
default-init-method="afterPropertiesSet"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Listeners -->
<bean id="test.message.notification.listener" class="com.test.message.listener.NotifMessageListener" />
<!-- Destinations -->
<bean id="test.message.notification.destination" class="com.liferay.portal.kernel.messaging.SerialDestination">
<property name="name" value="test/message/notification/destination" />
</bean>
<!-- Configurator -->
<bean id="messagingConfigurator" class="com.liferay.portal.kernel.messaging.config.PluginMessagingConfigurator">
<property name="messageListeners">
<map key-type="java.lang.String" value-type="java.util.List">
<entry key="test/message/notification/destination">
<list value-type="com.liferay.portal.kernel.messaging.MessageListener">
<ref bean="test.message.notification.listener" />
</list>
</entry>
</map>
</property>
<property name="destinations">
<list>
<ref bean="test.message.notification.destination"/>
</list>
</property>
</bean>
</beans>
2. under META-INFadd in ext-spring.xml
<import resource="message-spring.xml" />
3.under test.message.notification.listener create NotifMessageListener.java
public class NotifMessageListener implements MessageListener {
private static final Log LOG = LogFactoryUtil.getLog(NotifMessageListener.class);
@Override
public void receive(Message message) throws MessageListenerException {
try {
doReceive(message);
} catch (Exception e) {
LOG.error("Unable to process message " + message, e);
}
}
/**
*
* @param message
*/
protected void doReceive(Message message) {
long companyId = (Long) message.get("companyId");
long programId = (Long) message.get("programId");
long userId = (Long) message.get("userId");
long opinioSurveyId = (Long) message.get("opinioSurveyId");
LOG.info("Process notification if defined in the alert category[companyId="
+ companyId + ", programId=" + programId + ", userId=" + userId +
", opinioSurveyId=" + opinioSurveyId + "]");
// Process the notification
AddAlertToQueueUtil.addAlertToQueue(companyId, programId, userId, opinioSurveyId);
}
}
public class MessageBusConstants {
public static final String NOTIFICATION_MESSAGE = "test/message/notification/destination";
}
5.how to call messgeBus method
Message notificationMsg = new Message();
notificationMsg.put("companyId", srvy.getCompanyId());
notificationMsg.put("programId", ParamUtil.getLong(actionRequest, "programId", 0));
notificationMsg.put("userId", srvy.getUserId());
notificationMsg.put("opinioSurveyId", srvy.getOpinioSurveyId());
MessageBusUtil.sendMessage(MessageBusConstants.NOTIFICATION_MESSAGE, notificationMsg);
END.