WebsphereCommerce和ActiveMQ集成

    花了三天终于在Websphere commerce 7,实现了和activeMQ的JMS异步通行。

    业务流程如下:WCS作为前台商店,需要定时的往后台系统异步发送Order的数据。这里JMS Provider采用的是activeMQ(IBM Websphere MQ)买不起啊。其实和Websphere MQ的集成方式类似。

    记录下整个实现方式:

    1、在Websphere application server 管理控制台中配置:

       点击进入http://localhost:9060/ibm/console/login.do

       资源=》JMS 

        a.新建JMS提供程序

             选择“JMS提供程序”,选择作用域(节点=localhost,服务器=server1),点击“新建”

             

名称ActiveMQ
外部初始上下文工厂org.apache.activemq.jndi.ActiveMQWASInitialContextFactory
外部提供程序URLtcp://localhost:61616(这是activeMQ默认的连接地址)。

         

        b.然后,点击定制属性。新建

名称java.naming.queue.jms.orderProvider
jms/orderProvider
类型java.lang.String

        c.新建队列连接工厂 

              选择“队列连接工厂”,新建,JMS提供程序选择“ActiveMQ”。

             

名称Queue Connection Factory
JNDI名称QueueConnectionFactory
外部JNDI名称QueueConnectionFactory

         d.新建队列

                选择“队列连接工厂”,新建

名称OrderProvider
JNDI名称jms/orderProvider
外部JNDI名称jms/orderProvider

        对应资源文件:cells/localhost/nodes/localhost/servers/server1/resources.xml

        保存,重启AppServer.

    2、进入IBM WebSphere Commerce Administrator Console管理控制台,  选择“站点” 

         a.点击“配置”=> “传送”,选择“Websphere MQ”,点击“配置”。

工厂QueueConnectionFactory
入站队列jms/orderProvider
错误队列jms/orderProvider
错误队列jms/orderProvider

        

        这里我把inbound,outbound,errorbound都通过一个queue发送出去。也可以设置多个队列发送。

        对应配置文件,在wc-server.xml中

<OutboundConnector default="true" enabled="true" id="3"
                name="JMS" retries="3">
                <JNDI JndiName="eis/JCAJMS" display="false"/>
                <ConnectionSpec
                    ClassName="com.ibm.commerce.messaging.adapters.jcajms.JCAJMSConnectionSpec" default="true">
                    <EditableProperty Admin="factory" display="false"
                        editable="Yes" name="setConnectionFactory" value="QueueConnectionFactory"/>
                    <EditableProperty Admin="inQueue" display="false"
                        editable="Yes" name="setInboundQueue" value="jms/orderProvider"/>
                    <EditableProperty Admin="errorQueue" display="false"
                        editable="Yes" name="setErrorQueue" value="jms/orderProvider"/>
                    <EditableProperty Admin="outQueue" display="false"
                        editable="Yes" name="setOutboundQueue" value="jms/orderProvider"/>
                </ConnectionSpec>
                <InteractionSpec
                    ClassName="com.ibm.commerce.messaging.adapters.jcajms.JCAJMSInteractionSpec" default="true">
                    <EditableProperty Admin="timeOut" display="false"
                        editable="Yes" name="setTimeOut" value="60"/>
                    <EditableProperty Admin="mode" display="false"
                        editable="Yes" name="setMode" value="0"/>
                    <EditableProperty Admin="JMSExpiration"
                        display="false" editable="Yes"
                        name="setJMSExpiration" value="0"/>
                </InteractionSpec>
            </OutboundConnector>

         

          b.配置消息类型

               消息类型:可以定制,这里我选择已有功能“WebSphere Commerce XML 订单创建操作的出站消息”

               消息严重性:对应优先级别,1-9

               传输:Websphere MQ

               设备格式:Websphere MQ 适配器 (XML)

               错误队列:jms/orderProvider

               工厂:QueueConnectionFactory

               入站队列:jms/orderProvider

               出站队列:jms/orderProvider

               对应于表:PROFILE。

               这里可以新建消息类型。在MSGTYPES中。定义需要的消息数据。

               

    3、新建Command,名为ScheduledOrderProduceCmdImpl

package com.activemq.commerce.provider;


import com.ibm.commerce.command.CommandFactory;
import com.ibm.commerce.command.ControllerCommandImpl;
import com.ibm.commerce.datatype.TypedProperty;
import com.ibm.commerce.exception.ECException;
import com.ibm.commerce.messaging.commands.SendMsgCmd;
import com.ibm.commerce.ras.ECTrace;
import com.ibm.commerce.ras.ECTraceIdentifiers; 

import com.ibm.websphere.command.CacheableCommand;


public class ScheduledOrderProduceCmdImpl extends ControllerCommandImpl
		implements ScheduledOrderProduceCmd,CacheableCommand {

	public final static String COPYRIGHT = com.ibm.commerce.copyright.IBMCopyright.SHORT_COPYRIGHT;

	private static final String CLASS_NAME = "com.activemq.commerce.provider.ScheduledOrderProduceCmdImpl";

	public void performExecute() throws ECException {

		final String methodName = "performExecute()";

		ECTrace.entry(ECTraceIdentifiers.COMPONENT_EXTERN, CLASS_NAME,
				methodName);

		super.performExecute();
		
		SendMsgCmd senMsgCmdTask = (SendMsgCmd) CommandFactory
		.createCommand(SendMsgCmd.class.getName(),this.getStoreId());
		//对应的调用MSG的Command或者View
		senMsgCmdTask.setMsgType("OrderCreateXMLFormat");
		
		senMsgCmdTask.setCommandContext(getCommandContext());
		senMsgCmdTask.setStoreID(this.getStoreId());
		//设置优先级别,必须在最高和最低级别之间
		senMsgCmdTask.setPriority(3);
		
		TypedProperty tp = new TypedProperty();
		//设置订单ID
		tp.put("OrderRefNumber",11501);
		//设置语言类型
		tp.put("LANGUAGE_ID", getCommandContext().getLanguageId());
		//从JSP组装输出内容
		//viewName设置为null,默认从MSGTYPES表中取出对应view
		senMsgCmdTask.compose(null,getCommandContext(),tp);
		//直接输入字符来设置输出内容
		//senMsgCmdTask.setContent(3,"-7","hello world");
		senMsgCmdTask.sendImmediate();
		
		senMsgCmdTask.execute();
		
		ECTrace.exit(ECTraceIdentifiers.COMPONENT_EXTERN, CLASS_NAME,
				methodName);

	}

}

                    

    4、在struts-config.xml中配置view.

 

<forward className="com.ibm.commerce.struts.ECActionForward"
            name="OrderCreateXMLFormatView/10001/-4" path="/OrderCreateXML.jsp">
            <set-property property="direct" value="true"/>
            <set-property property="resourceClassName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl"/>
            <set-property property="interfaceName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommand"/>
            <set-property property="properties" value="storeDir=no"/>
            <set-property property="implClassName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl"/>
</forward>
<action path="/OrderCreateXMLFormatView" type="com.ibm.commerce.struts.BaseAction">
            <set-property property="https" value="0:0"/>
</action>

    这里:

             10001表示storeId,站点级别设置为0。

             -4 表示设备格式。对应格式所代表的数字如下:

SOAP XML data transmitted via HTTP = -1
HTTP Browser = Reserved for IBM 
Standard Device Format = -3
WebSphere MQ Adapter for XML = -4
WebSphere MQ Adapter for WCS (Legacy message) = -5

          

   5、启动acitveMq,调用上面的command,即会已XML格式发送一个orderId=11501的订单信息,到activeMQ broker,consumer即可消费该消息。   

相关推荐