OFBiz JMS ACTIVEMQ

Source: Internet
Author: User

Recently in the study of OFBiz JMS, played with ACTIVEMQ, ofbiz use Jndi and other JMS to receive and send messages, summed up.

Prepare

ofbiz12.04 version

ACTIVEMQ version 5.5


Jar Package

Introducing the package under Base/lib

Activemq-all-5.5.0.jar

Geronimo-j2ee-management_1.1_spec-1.0.1.jar


Service engine Configuration

<span style= "FONT-SIZE:14PX;" ><jms-service name= "Servicemessenger" send-mode= "All" >            <server jndi-server-name= "Default"                    Jndi-name= "Topicconnectionfactory"                    topic-queue= "ofbtopic"                    type= "topic"                    listen= "true"/>        < /jms-service></span>

jndi.properties Configuration

<span style= "FONT-SIZE:14PX;" >java.naming.factory.initial=org.apache.activemq.jndi.activemqinitialcontextfactoryjava.naming.provider.url =tcp://127.0.0.1:61616topic. Ofbtopic=ofbtopicconnectionfactorynames=connectionfactory, Queueconnectionfactory, topicConnectionFactory</ Span>

Try only one topic message mode, if you want to use queue queues, configure

<span style= "FONT-SIZE:14PX;" >queue. Ofbqueue= ofbqueue</span>

Test

Start Activemq First, then start ofbiz

OFBiz after startup see:

<span style= "FONT-SIZE:14PX;"  >2015-01-15 11:47:56,970 ([email protected]) [Jmslistenerfactory.java:89:info] JMS Listener Factory Thread finished; All listeners connected.</span>
if the report fails to monitor, you find out what the problem.

And then look at the ACTIVEMQ console.



Message Sending and Receiving

We are using ofbiz to give the test example:

Services_test.xml

<span style= "FONT-SIZE:14PX;" ><service name= "Testjmstopic" engine= "JMS" location= "Servicemessenger" invoke= "TESTSCV" >        < Description>test JMS Topic service</description>        <attribute name= "message" type= "String" mode= "in"/ >    </service></span>

Run this service to see the effect:

<span style= "FONT-SIZE:14PX;" >2015-01-15 12:09:10,754 (ActiveMQ Session Task-1) [Modelservice.java:469:info] Set default value [999.9999] fo R parameter [defaultvalue]2015-01-15 12:09:10,755 (ActiveMQ Session Task-1) [Serviceecarule.java:137:info] for Servi  Ce ECA [TESTSCV] on [invoke] got false for condition: [message][equals][auto][true][string]----Svc-context:message = Test topic message----Svc-context:locale = ZH_CN----Svc-context:timezone = sun.util.calendar.zoneinfo[id= "asia/ Shanghai ", Offset=28800000,dstsavings=0,usedaylight=false,transitions=19,lastrule=null]----SVC-CONTEXT: Userlogin = [genericentity:userlogin][createdstamp,2014-07-17 20:36:06.0 (Java.sql.Timestamp)][createdtxstamp, 2014-07-17 20:36:06.0 (Java.sql.Timestamp)][currentpassword,{sha}47ca69ebb4bdc9ae0adec130880165d2cc05db1a ( java.lang.String)][enabled,y (java.lang.String)][hasloggedout,n (java.lang.String)][lasttimezone,asia/macao ( java.lang.String)][lastupdatedstamp,2014-11-26 16:12:57.0 (jAva.sql.Timestamp)][lastupdatedtxstamp,2014-11-26 16:12:57.0 (java.sql.Timestamp)][partyid,admin ( java.lang.String)][successivefailedlogins,0 (Java.lang.Long)][userloginid,admin (java.lang.String)]---- Svc-context:defaultvalue = 999.9999-----SERVICE Test-----: Test Topic message-----svc:entity-default-----</span>
look at the ACTIVEMQ console .



into row message one, receive a message.

Explain why this is going to happen.

We run the service to send a broadcast message, which is why messages enqueued has a piece of data, so why messages Dequeued also has a message, because OFBiz is also the client side of the server, we set up the listener is not.


OFBiz as a service side

All we have to do is look at the JMS service engine and understand, not much.


OFBiz as a client

How does this piece play?

First we set the listener to true in the service engine configuration file,

Second, let's look at the load of Jmslistenerfactory.java from the service engine configuration file after the service engine is loaded and the JMS listener is loaded.

Finally, put out a piece of code

Jmstopiclistener.java

<span style= "FONT-SIZE:14PX;" > Public synchronized void Load () throws Genericserviceexception {try {initialcontext Jndi = Jndico            Ntextfactory.getinitialcontext (Jndiserver);            Topicconnectionfactory factory = (topicconnectionfactory) jndi.lookup (jndiname);                if (factory! = null) {con = factory.createtopicconnection (userName, password);                Con.setexceptionlistener (this);                Session = Con.createtopicsession (false, Session.auto_acknowledge);                TOPIC = (Topic) jndi.lookup (topicname);                    if (topic! = NULL) {TopicSubscriber subscriber = session.createsubscriber (topic);                    Subscriber.setmessagelistener (this);                    Con.start ();                    This.setconnected (TRUE);                if (Debug.infoon ()) Debug.loginfo ("Listening to topic [" + Topicname + "] on [" + Jndiserver + "] ...", module);                 } else {   throw new Genericserviceexception ("Topic lookup failed.");            }} else {throw new Genericserviceexception ("Factory (broker) lookup failed."); }} catch (Namingexception ne) {throw new Genericserviceexception ("JNDI lookup problems;        Listener not running. ", NE); } catch (JMSException je) {throw new Genericserviceexception ("JMS internal error;        Listener not running. ", je); } catch (Generalexception ge) {throw new Genericserviceexception ("Problems with InitialContext;        Listener not running. ", GE); }}</span>


At the time, there was another question, what did ofbiz do after listening to the message after hearing the event?

Similarly, by pasting a piece of code, we all understand:

Abstractjmslistener.java

<span style= "FONT-SIZE:14PX;" >/**     * Receives the mapmessage and processes the service.     * @see javax.jms.messagelistener#onmessage (message)     */public    void onMessage (Message message) {        Mapmessage mapmessage = null;        if (Debug.verboseon ()) debug.logverbose ("JMS Message Received--" + message, module);        if (message instanceof mapmessage) {            mapmessage = (mapmessage) message;        } else {            debug.logerror ("Received Message is not a mapmessage! ", module);            return;        }        Runservice (mapmessage);    } </span>

<span style= "FONT-SIZE:14PX;" >/** * Runs the service defined in the mapmessage * @param message * @return Map */protected MAP&LT ;        String, object> runservice (Mapmessage message) {map<string,? extends object> context = null;        String serviceName = null;        String xmlcontext = null;            try {serviceName = message.getstring ("ServiceName");            Xmlcontext = message.getstring ("Servicecontext"); if (ServiceName = = NULL | | xmlcontext = = NULL) {Debug.logerror ("Message received is not a OFB service mes Sage.                ignored! ", module);            return null;            } Object o = Xmlserializer.deserialize (Xmlcontext, Dispatcher.getdelegator ());            if (Debug.verboseon ()) debug.logverbose ("De-serialized Context--and" + O, module);        if (objecttype.instanceof (O, "java.util.Map")) context = Utilgenerics.checkmap (o);      } catch (JMSException je) {      Debug.logerror (JE, "problems reading message.", module);        } catch (Exception e) {debug.logerror (E, "problems deserializing the service context.", module);            } try {Modelservice model = Dispatcher.getdispatchcontext (). Getmodelservice (ServiceName);                if (!model.export) {debug.logwarning ("Attempt to invoke a non-exported service:" + serviceName, module);            return null; }} catch (Genericserviceexception e) {debug.logerror (E, "Unable to get modelservice for service:" +        ServiceName, module);        } if (Debug.verboseon ()) debug.logverbose ("Running service:" + serviceName, module);        map<string, object> result = null;            if (context = null) {try {result = Dispatcher.runsync (serviceName, context); } catch (Genericserviceexception GSE) {debug.logerror (GSE, "problems with service invocation.", Module);    }} return result; }</span>


Note

You can configure both queue and broadcast mode messages, configure the same as above and refer to the active MQ official website for Jndi support


Reference

OFBiz jms:https://cwiki.apache.org/confluence/display/ofbiz/distributed+entity+cache+clear+ (DCC) +Mechanism

ACTIVEMQ jndi:http://activemq.apache.org/jndi-support.html



OFBiz JMS ACTIVEMQ

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.