Liferay messagebus configure.

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);
	}
}


4.add constants file 

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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值