JMS, jmswebservice

Source: Internet
Author: User

JMS, jmswebservice

The following documents are provided on the ActiveMQ official website.
Http://activemq.apache.org/spring-support.html

Below are some dependencies I have added:

<!-- jms activemq --><dependency>    <groupId>javax.jms</groupId>    <artifactId>javax.jms-api</artifactId>    <version>2.0</version></dependency><dependency>    <groupId>org.apache.activemq</groupId>    <artifactId>activemq-core</artifactId>    <version>${activemq.version}</version></dependency><dependency>    <groupId>org.apache.activemq</groupId>    <artifactId>activemq-pool</artifactId>    <version>${activemq.version}</version></dependency><dependency>    <groupId>org.apache.activemq</groupId>    <artifactId>activemq-spring</artifactId>    <version>${activemq.version}</version></dependency><dependency>    <groupId>org.apache.xbean</groupId>    <artifactId>xbean-spring</artifactId>    <version>3.16</version></dependency><dependency>    <groupId>org.springframework</groupId>    <artifactId>spring-jms</artifactId>    <version>${spring.version}</version></dependency>

 

Note that xbean-spring is added to maven;
I did not pay attention to it before. The exception prompt ClassNotFound: org. apache. xbean. spring. context. v2.XBeanNamespaceHandler is displayed during running;
Later I added the xbean-v2 and the result showed v2c, so I added v2c, and then I felt too silly to add xbean-spring.

The labels of jms and activeMq can be used for Configuration:

xmlns:amq="http://activemq.apache.org/schema/core"xmlns:jms="http://www.springframework.org/schema/jms"

 

Corresponding xsi: schemaLocation:

http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsdhttp://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd

 

For connectionFactory configuration, you can use the amq Tag:

<amq:connectionFactory id="jmsFactory" brokerURL="tcp://localhost:61616" />

 

But here I plan to try PooledConnectionFactory;
The official website of org. apache. activemq. pool. PooledConnectionFactory has the following explanations:
If you are not using a JCA container to manage your JMS connections, we recommend you use our pooling JMS connection provider, (org. apache. activemq. pool. pooledConnectionFactory) from the activemq-pool library, which will pool the JMS resources to work efficiently with Spring's JmsTemplate or with EJBs.

 

For its attributes, the following are some explanations based on javaDoc:
· MaximumActiveSessionPerConnection: Maximum number of sessions for each Connection
· BlockIfSessionPoolIsFull: by default, requests are blocked when the session pool is full. If it is set to false, JMSException is thrown.
· MaxConnections: Maximum number of connections
· IdleTimeout: idle time. The default value is 30 seconds.
· CreateConnectionOnStartup: whether to create a connection at startup

 

Here I use the default parameter declaration first. I don't know why MalformPrameterizedType is always reported...

<Bean id = "jmsFactory" class = "org. apache. activemq. pool. PooledConnectionFactory"/>
The queue used last time. Try replacing Topic this time...

<bean id="destination" class="org.apache.activemq.command.ActiveMQTopic">  <constructor-arg index="0" value="spartaTopic"></constructor-arg></bean>

 

Of course, you can also use the amq Tag:

<amq:topic physicalName="sparta" />

 

If queue is used:

<amq:queue physicalName="sparta" />

 

Do I put these in spring to facilitate DI with labels?
In <spring in action>, jmsTemplate is <core part of spring's support for jms>
(JmsTemplate102 is applicable to jms1.0.2 );
JmsTemplate has similar advantages as jdbcTemplate.
For example, jdbcTemplate processes out-of-control jdbc code, and jmsTemplate is used to process out-of-control jms code.
Alternatively, if JmsTemplate is used to capture JMSException, JmsTemplate will capture this exception and then throw a subclass exception of JmsException that comes with Spring (I personally feel that spring does not provide more detailed exception information, but the focus is different ...).

 

For example:
· ListenerExecutionFailedException: Listener execution failed
· MessageConversionException: Message Conversion failed
· SynchedLocalTransactionFailedException: synchronization of local transactions is not completed
· UncategorizedJmsException: no other exception situations are suitable.
If we catch JMSException, we can still convert it to JmsException:

catch (JMSException e) {            e.printStackTrace();            JmsException je = JmsUtils.convertJmsAccessException(e);        }

 

Now try to configure jmsTemplate:

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" >    <property name="connectionFactory" >        <bean class="org.apache.activemq.pool.PooledConnectionFactory" />    </property>    <property name="defaultDestination" >        <amq:topic physicalName="sparta" />    </property></bean>

 

In this way, the code writing becomes much simpler, and those connectionFactory, connection, session, consumer, and producer are all gone;
I only need to use template:

ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");JmsTemplate template = (JmsTemplate)context.getBean("jmsTemplate");template.send(new MessageCreator() {    public Message createMessage(Session session) throws JMSException {        ActiveMQMapMessage msg = (ActiveMQMapMessage)session.createMapMessage();        msg.setString("msg", "This is sparta!!");        return msg;    }});

 

Template. receive ();

But pay attention to it! This receive receives messages synchronously, and it will be blocked until a message is received.
You may think of MessageListener. For example, we can give a MessageConsumer object setMessageListener:

MessageConsumer consumer = session.createConsumer(destination);consumer.setMessageListener(new MessageListener() {    public void onMessage(Message message) {        try {            System.out.println("listener catched:::"+((TextMessage)message).getText());        } catch (JMSException e) {            e.printStackTrace();        }    }});

 

In the MessageListener instance in the above Code, if you create a class specifically for listening, implement the MessageListener interface, and add the MessageDriven annotation, a problem will occur-he is not enough for pojo. He is invasive and I don't want any syntax that implements the interface to appear in the code.

So I can use listener-container;
Now I create a class to listen to, for example:

public class CustomedListener {    void processHandle(HashMap<String,String> map){        System.out.println("msg:::"+map.get("msg"));    }}

 

The message sent by publisher above is ActiveMQMapMessage, which requires the parameter to be defined as the form above.
Then let's take a look at how to configure this Listener in spring:

<bean id="myListener" class="pac.testcase.jms.CustomedListener"/><jms:listener-container connection-factory="connectionFactory">    <jms:listener destination="sparta" ref="myListener" method="processHandle"/></jms:listener-container>

 

In this way, I do not need to call receive and receive messages.


What is "JMS" on the Internet?

That's what sisters mean. You're right.

Mm: Sister

Gg: Brother

Dd: younger brother

Jj: Sister

Plmm: Pretty girl

Xdjm: siblings

Pfpf: admire

Pp: photo, but if it is pp, it means kick your ass.

Bt: abnormal. Compared with other sections of the cloud, the water version is a place where bt is found (she, it)

Zt: Re-posting, sometimes abbreviated as z.

Sl: Color wolf.

Bl: glass, not fragile, but gay

Bc: Idiot

Bd: Dumb

Ry: Demon

Lm: rogue

Pg: ass

Gf: girl friend, girlfriend

Bf: boy friend, boyfriend

Md: Damn it, you can use it with caution!

Tmd: ***, with a thick mouth, especially with caution!

Jjww: the way people speak

Sjb: Neurology

Pmp: flattering

Mpj: Butlers

Kick: Flat
Kh: sunflower is the master of the sunflower collection. A certain yunyun master has been trained in the environment, so no one calls its name, but calls it directly.

Khbd: sunflower collection

Pxjf

Js: profiteer

Sp: support, supported

Micro: a tone Auxiliary Word, dedicated for kh

Call, pig: Sleep

Porridge: Yes

Jam: Award

Bxcm: ice and snow smart

Lol: laugh out loud, laugh

Kfc: kxxx & fxxx & cxx

Pk: player kill, hacker, attack, can also be interpreted as the first batch after k

Btw: by the way, by the way

Ps: two meanings: btw or photoshop (a computer image repair software)

Cu: see you, goodbye

Bb: Baby, lover, child, byebye

Although Zhao Gong: super powerful

Manqing: manqing's ten torture techniques and the playfulness of our ancestors

Click it: cut down

Sauce purple: This way

Meals: meals

Film: Same pp, photo

Banzhu and Banzhu: moderators and forum administrators compare the water version to a small store.

Water Bucket, water ghost, Narcissus, Water King, water monster, jellyfish: refers to the irrigation madman, Jellyfish Special Women

Sailors: all sentient beings in the edition

Diver

Dinosaur: ugly mm

Crazy: unable to cope with the stimulus and abnormal behavior

Thx, 3x: thanks, thank you

Sigh: sigh

Cool: cool

Gay: gay, bl

Fag: Gay, bl

Pm: private messages of the Forum

Zip it: Shut up

Leecher: a vampire. It refers to a person who only knows how to ask for a shared reward and is severely despised.

Dl: download, download

Pub: ftp scanned on the Internet. It can temporarily upload and download files, or upload files to pubftp for sharing.

Brb: be right back, coming back soon

Ttyl: talk to you later.

Bbl: be back later will be back later

Kick your ass: Beat your ass

Ppl: people

Plz, pls: please, please

Bull ***, ***: Nonsense

Sorry ass: Poor guy, despising

So: General

Cutie: Sweetheart

D \ * amn: Depends on, he xx

Steamed Stuffed bun: Someone is ugly or stupid.

Powder: Very, Very

Cainiao, prawns, and beginners: New beginners

Laruence, prawns: Master

Wood Oil: No

Protein: bd + bc + sjb

Love Tiger Oil: I love u, I love you

Inverted: fainting, reverse

Table: No. For example, the table is too good.

When: faint sound

9494: that is

Pig doll: A good oral English from ccf

Explosive head: the words in the game, taking some... the rest of the full text>

What is "JMS" on the Internet?

That's what sisters mean. You're right.

Mm: Sister

Gg: Brother

Dd: younger brother

Jj: Sister

Plmm: Pretty girl

Xdjm: siblings

Pfpf: admire

Pp: photo, but if it is pp, it means kick your ass.

Bt: abnormal. Compared with other sections of the cloud, the water version is a place where bt is found (she, it)

Zt: Re-posting, sometimes abbreviated as z.

Sl: Color wolf.

Bl: glass, not fragile, but gay

Bc: Idiot

Bd: Dumb

Ry: Demon

Lm: rogue

Pg: ass

Gf: girl friend, girlfriend

Bf: boy friend, boyfriend

Md: Damn it, you can use it with caution!

Tmd: ***, with a thick mouth, especially with caution!

Jjww: the way people speak

Sjb: Neurology

Pmp: flattering

Mpj: Butlers

Kick: Flat
Kh: sunflower is the master of the sunflower collection. A certain yunyun master has been trained in the environment, so no one calls its name, but calls it directly.

Khbd: sunflower collection

Pxjf

Js: profiteer

Sp: support, supported

Micro: a tone Auxiliary Word, dedicated for kh

Call, pig: Sleep

Porridge: Yes

Jam: Award

Bxcm: ice and snow smart

Lol: laugh out loud, laugh

Kfc: kxxx & fxxx & cxx

Pk: player kill, hacker, attack, can also be interpreted as the first batch after k

Btw: by the way, by the way

Ps: two meanings: btw or photoshop (a computer image repair software)

Cu: see you, goodbye

Bb: Baby, lover, child, byebye

Although Zhao Gong: super powerful

Manqing: manqing's ten torture techniques and the playfulness of our ancestors

Click it: cut down

Sauce purple: This way

Meals: meals

Film: Same pp, photo

Banzhu and Banzhu: moderators and forum administrators compare the water version to a small store.

Water Bucket, water ghost, Narcissus, Water King, water monster, jellyfish: refers to the irrigation madman, Jellyfish Special Women

Sailors: all sentient beings in the edition

Diver

Dinosaur: ugly mm

Crazy: unable to cope with the stimulus and abnormal behavior

Thx, 3x: thanks, thank you

Sigh: sigh

Cool: cool

Gay: gay, bl

Fag: Gay, bl

Pm: private messages of the Forum

Zip it: Shut up

Leecher: a vampire. It refers to a person who only knows how to ask for a shared reward and is severely despised.

Dl: download, download

Pub: ftp scanned on the Internet. It can temporarily upload and download files, or upload files to pubftp for sharing.

Brb: be right back, coming back soon

Ttyl: talk to you later.

Bbl: be back later will be back later

Kick your ass: Beat your ass

Ppl: people

Plz, pls: please, please

Bull ***, ***: Nonsense

Sorry ass: Poor guy, despising

So: General

Cutie: Sweetheart

D \ * amn: Depends on, he xx

Steamed Stuffed bun: Someone is ugly or stupid.

Powder: Very, Very

Cainiao, prawns, and beginners: New beginners

Laruence, prawns: Master

Wood Oil: No

Protein: bd + bc + sjb

Love Tiger Oil: I love u, I love you

Inverted: fainting, reverse

Table: No. For example, the table is too good.

When: faint sound

9494: that is

Pig doll: A good oral English from ccf

Explosive head: the words in the game, taking some... the rest of the full text>

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.