package com.ndung;
import javax.jms.*;
import org.apache.activemq.ActiveMQConnectionFactory;
public class HelloWorldProducer {
public static void main(String[] args) throws JMSException {
//Instantiate connection factory, specific to the vendor
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue("TEST.MQ");
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(destination);
// Create a messages
String text = "Hello world! From: ndung";
TextMessage message = session.createTextMessage(text);
// Tell the producer to send the message
System.out.println("Message Sent");
producer.send(message);
// Clean up
session.close();
connection.close();
}
}
package com.ndung;
import javax.jms.*;
import org.apache.activemq.ActiveMQConnectionFactory;
public class HelloWorldConsumer {
public static void main(String[] args) throws JMSException {
//Instantiate connection factory, specific to the vendor
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue("TEST.MQ");
// Create a MessageConsumer from the Session to the Topic or Queue
MessageConsumer consumer = session.createConsumer(destination);
// Wait for a message
Message message = consumer.receive(1000);
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
System.out.println("Received: " + text);
} else {
System.out.println("Received: " + message);
}
consumer.close();
session.close();
connection.close();
}
}
In the previous post, we have been introduced into EAI (Enterprise Application Integration) and a flash on Middleware. There are two fundamentally different types of middleware based on the approach used by the middleware to transfer the data between the distributed software applications. They are Remote Procedure Calls (RPC) based middleware and Message-oriented Middleware (MOM).
1. RPC. Software application that uses RPC based middleware to transfer data to another software application has to wait until the latter application is done processing the data. Thus, with this type of middleware, the communication proceeds in a lock step, synchronized manner, and the communicating processes are tightly coupled to one another. Examples of such middleware include Java RMI, CORBA, etc.
2. MOM. Is best described as a category of software for communication in an loosely-coupled, reliable, scalable, enabled asynchronous communication amongst distributed applications or systems.
JMS is a spesification that defines a set of interfaces and associated semantics, which allow applications written in Java to access the services of any JMS compliant Message MOM product. There are plenty of compliant MOM products available in market, including MQSeries from IBM, SonicMQ from Progress, Sun Java Message Queue, even Apache ActiveMQ, and many more.
The players in JMS:
1. Connections and Connection Factories
2. Sessions
3. Destinations
We should try first JMS First Impression using ActiveMQ in here. I'm using Netbeans 6.5 as IDE and prepare library: activemq-all-5.2.0.jar and jms.jar.
There are two different types of MOM: point-to-point and publish-and-subscribe.
1. Point-to-Point messaging style. In this model, a MOM is used by two applications to communicate with each other, often as an asynchronous replacement for remote procedure calls (RPC).
2. Publish-and-Subscribe messaging style. In this model multiple applications connect to the MOM as their publishers, which are producers of messages, or subscribers, which are consumers of messages. An important point of difference between the two styles is that a a point-to-point system is typically either a one-to-one system, which means one message sender talking to one message receiver, or it is a a many-to-one system, which means more than one senders are talking to one receiver. On the other hand, publish-and-subscribe systems are typically many-to-many systems, which means that there could be one or more publishers talking to one or more subscribers at a time.
Simple PTP (Point-to-Point) Application and Pub/Sub (Publisher and Subscriber) Application
We will enhance sample above by setting up activemq broker first and using JNDI. Configuring JNDI web application in Tomcat container can read in here. After we extract apache-activemq-5.2.0.rar that we have downloaded, edit activemq.xml that placed in folder conf. Delete all "multicast" in this configuration file. After that, enter folder bin, and run activemq. In the same project with above create packages named com.ndung.ptp and com.ndung.ps. Create new two java classes named SimpleQueueSender.java and SimpleQueueReceiver.java in com.ndung.ptp package and create new two java classes named SimpleTopicPublisher.java and SimpleTopicSubscriber in com.ndung.ps package.
package com.ndung.ptp;
import java.util.Properties;
import javax.jms.*;
import javax.naming.*;
public class SimpleQueueSender {
public static void main(String[] args) throws NamingException, JMSException {
String queueName = "PTP.ACTIVE.MQ";
//setting JNDI configuration, differents between vendors.
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
props.setProperty(Context.PROVIDER_URL,"tcp://localhost:61616");
Context jndiContext = new InitialContext(props);
ConnectionFactory queueConnectionFactory = (ConnectionFactory)
jndiContext.lookup("ConnectionFactory");
QueueConnection queueConnection = (QueueConnection)
queueConnectionFactory.createConnection();
QueueSession queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(queueName);
QueueSender queueSender = queueSession.createSender(queue);
queueConnection.start();
TextMessage textMessage = queueSession.createTextMessage();
textMessage.setText("Hello World");
queueSender.send(textMessage);
queueSession.close();
queueConnection.close();
}
}
package com.ndung.ptp;
import java.util.Properties;
import javax.jms.*;
import javax.naming.*;
public class SimpleQueueReceiver {
public static void main(String[] args) throws JMSException, NamingException {
String queueName = "PTP.ACTIVE.MQ";
//setting JNDI configuration, differents between vendors.
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
props.setProperty(Context.PROVIDER_URL,"tcp://localhost:61616");
Context jndiContext = new InitialContext(props);
ConnectionFactory queueConnectionFactory = (ConnectionFactory)
jndiContext.lookup("ConnectionFactory");
QueueConnection queueConnection = (QueueConnection)
queueConnectionFactory.createConnection();
QueueSession queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(queueName);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
queueConnection.start();
TextMessage textMessage = (TextMessage) queueReceiver.receive();
System.out.println(textMessage);
queueSession.close();
queueConnection.close();
}
}
package com.ndung.ps;
import java.util.Properties;
import javax.jms.*;
import javax.naming.*;
public class SimpleTopicPublisher {
public static void main(String[] args) throws Exception {
try {
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
props.setProperty(Context.PROVIDER_URL,"tcp://localhost:61616");
Context jndiContext = new InitialContext(props);
ConnectionFactory myConnectionFactory = (ConnectionFactory)
jndiContext.lookup("ConnectionFactory");
// Use myConnectionFactory to get a Topic connection
TopicConnection myConnection = (TopicConnection)
myConnectionFactory.createConnection();
// Use myConnection to create a Topic session
TopicSession mySession = myConnection.createTopicSession(false, 1);
// Use mySession to get the Topic
Topic myTopic = mySession.createTopic("PS.ACTIVE.MQ");
// Use mySession to create a publisher for myTopic
TopicPublisher myPublisher = mySession.createPublisher(myTopic);
// Start the connection
myConnection.start();
// Create the HelloWorld message
TextMessage m = mySession.createTextMessage();
m.setText("Hello World");
// Use myPublisher to publish the message
myPublisher.publish(m);
// Done.
// Need to clean up
mySession.close();
myConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.ndung.ps;
import java.util.Properties;
import javax.jms.*;
import javax.naming.*;
public class SimpleTopicSubscriber {
public static void main(String[] args) {
try {
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
props.setProperty(Context.PROVIDER_URL,"tcp://localhost:61616");
Context jndiContext = new InitialContext(props);
ConnectionFactory myConnectionFactory = (ConnectionFactory)
jndiContext.lookup("ConnectionFactory");
// Use myConnectionFactory to get a Topic connection
TopicConnection myConnection = (TopicConnection)
myConnectionFactory.createConnection();
// Use myConnection to create a Topic session
TopicSession mySession = myConnection.createTopicSession(false, 1);
// Use mySession to get the Topic
Topic myTopic = mySession.createTopic("PS.ACTIVE.MQ");
// Use mySession to create a subscriber
TopicSubscriber mySubscriber = mySession.createSubscriber(myTopic);
// Start the connection
myConnection.start();
// Wait for the Hello World message
// Use the receiver and wait forever until the message arrives
TextMessage m = (TextMessage) mySubscriber.receive();
// Display the message
System.out.println("Received the message: " + m.getText());
// Done.
// Need to clean up
mySession.close();
myConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
To know the differences between PTP application and Pub/Sub application:
1. Run two instance of SimpleQueueReceiver and then run one instance of SimpleQueueSender. One of SimpleQueueReceiver got message from SimpleQueueSender and the other one didn't.
2. Run two instance of SimpleTopicSubscriber and then run one instance of SimpleTopicPublisher. We can look both of SimpleTopicSubsriber got message from SimpleTopicPublisher.
We can monitor message queue by running http://localhost:8161/admin in web browser. More better coding style in the next post.
327 comments:
«Oldest ‹Older 201 – 327 of 327buy xanax online San Antonio xanax side effects wiki - has bought xanax online
buy ambien ambien pill generic - ambien walrus tumblr
buy ambien much generic ambien - ambien and drinking alcohol
alprazolam no prescription generic xanax vs alprazolam - xanax bars effects
cheapest ambien ambien high stories - vicodin ambien and alcohol
generic xanax Colorado 1mg xanax good - xanax dosage weight dogs
buy ambien ambien walrus shirt - ambien and insomnia
buy xanax Oakland xanax side effects rash - xanax side effects eye twitching
buy xanax online xanax no prescription overnight - will 1mg xanax do
buy xanax online xanax interactions more drug_interactions - zoloft xanax withdrawal
ambien medication 2 ambien cr 12.5 - turn ambien light philips tv
buy ambien ambien during pregnancy first trimester - buy ambien cr generic
buy xanax Tucson xanax and alcohol withdrawal dosage - paxil for xanax for anxiety
ambien ambien for insomnia - effects of ambien overdose
buy xanax online no prescription xanax drug prescribed - can you buy xanax over counter
xanax pills order cheap xanax online no prescription - usual dosage xanax anxiety
buy alprazolam xanax 1mg dose - drug interactions for xanax
can you buy ambien online ambien side effects in men - chemical name drug ambien
buy xanax online overnight delivery order xanax pills online - can you buy xanax legally online
ambien 10 mg ambien discount coupon - can buy ambien online
xanax medication celexa xanax and alcohol - alprazolam 0.5 mg high
ambien without a rx ambien generic no prescription - buy real ambien online
buy xanax San Diego xanax generic price - non-prescription xanax online
buy xanax Massachusetts xanax withdrawal ringing ears - xanax drug fact sheet
xanax antidepressant xanax side effects slurred speech - xanax effects immune system
buy generic ambien ambience mall gurgaon kids zone - philips plasma tv ambien light
xanax order no prescription .5 xanax vs 1mg klonopin - xanax withdrawal time
cheap zolpidem ambien side effects bloating - ambien side effects migraine
buy xanax bars generic xanax pink pill - buy xanax from india
how to buy xanax online legally xanax generic online - xanax drug for sleep
ambien generic ambien dosage max - ambien side effects for men
buy xanax drug interaction between xanax and zoloft - xanax side effects euphoria
ambien cheap ambien generic gluten free - buy ambien online reviews
order ambien online no prescription buy ambien from india - ambien online no prescription
order xanax no prescription xanax .25 to get high - xanax online bluelight
buy ambien no prescription street price for ambien - que es ambien cr
order alprazolam generic pills for xanax pictures - buy xanax bars cheap
buy xanax Texas xanax bars u94 - alprazolam 0.5mg effects
buy xanax online Memphis order xanax online prescription - side effects xanax extended release
buy ambien ambien side effects tinnitus - ambien cr 25 mg dosage
cheap xanax no prescription effects taking 5 xanax - xanax 2mg side effects
ambien ambien sleeping pill effects - ambien generic 74 93
buy xanax Virginia buy xanax xr online - xanax bars yellow
xanax online Georgia xanax overdose seizures - xanax bars lil wyte
generic xanax New York xanax schedule 2 drug - norco xanax high
buy ambien ambien cr cost - ambien cr half pill
ambien online pharmacy ambien cr xanax interaction - ambien drug
buy alprazolam online xanax indications - images of generic xanax
xanax drug xanax bars long system - buy xanax online from u.k
ambien pills ambien facts - ambien wiki drug
xanax online Omaha xanax 1mg value - buy xanax online legitimate
xanax 1mg xanax drug test navy - buy xanax online no prescription cheap
where can i buy xanax online legally buy xanax online from canada - klonopin xanax drug test
buy xanax online xanax side effects pregnant women - xanax side effects appetite
buy ambien ambien overdose dosage - side effects long term ambien use
cheap ambien ambien side effects long term use - ambien pill number
buy xanax online drug test xanax long - effects xanax vicodin
buy ambien ambien generic pill identifier - can ambien overdose kill you
buy ambien online overnight delivery is ambien 10mg strong - ambien sleeping tablets online
where can i order xanax online how to order xanax - how long does 3mg xanax high last
cheap xanax xanax side effects rage - xanax grapefruit effects
where can i buy xanax online legally xanax generic brand name - xanax help zoloft withdrawal
purchase ambien how to purchase ambien - ambien high erowid
buy alprazolam 2mg xanax no tolerance - side effects from xanax drug
order ambien without prescriptions buy ambien online fast shipping - ambien side effects 2012
cheap alprazolam buy xanax no prescription needed - xanax dosage with food
buy xanax cheap effects xanax your body - xanax bars narcotic
buy ambien ambien side effects eating - ambien for children
buy ambien ambien buy india - ambien cr online
Welcome to shop the clarisonic products from the [url=http://www.clarisonicmiaaustralias.com]clarisonic australia[/url] online store.
viagra online without prescription buy viagra paypal accepted - cheap viagra online australia
http://greencoffeesiteme.net/ Diet Myth #3: Drink Water to Lose WeightWe've all seen someone around the office or at the gym lugging around a gallon of Sparkletts in the hopes that drinking water will help them lose weight. While there is certainly nothing harmful about indulging in this diet myth, there is no connection between consuming water and losing weight. The truth is that water does give you the energy you need throughout the day to burn calories and CAN help you feel fuller temporarily, but it does nothing to reduce the body's need to consume food. So rather than gorging on water all day, the best course of action is to drink enough water to keep your energy level up and to substitute water for any high-calorie drinks currently in your diet. The best thing about this is once you gain muscle it will automatically speed up your metabolism. This will lead to you burning calories and not having to think about it as much. [url=http://greencoffeesiteme.net/]http://florencegapk.livejournal.com/987.html[/url] List your obstacles for losing weight and brainstorm all the options for breaking through them. Pick out the best option for dealing with each obstacle and turn it into action. Executing your action plan can help you overcome your obstacles. I notice I am much more lively and have much more energy to get through my workouts, and thats just the beginning of the list. I sleep better, gain muscle much faster, and seem to get more out of my fat-blasting workouts. I highly recommend a Candida cleanse to anyone. This gives you a good mix of protein and fat, which are of import for keeping you hungriness at doable levels and giving you the fabrics you need to keep your muscles firm. Under no circumstances should you vamoose breakfast or not eat the full total. You may have java or tea with it, but make sure not to use sweeteners or any dairy products.
viagra online without prescription viagra dosage directions - can buy viagra online us
buy soma soma 350 mg recreational use - soma drug uses
generic soma buy soma from usa - does soma san diego have seats
buy cialis online cialis online fast shipping - buy cialis online fast delivery
purchase cialis cialis yahoo answers - best place to buy cialis online forum
buy tramadol online can you buy tramadol online - tramadol for dogs reviews
tramadol 100 ultram side effects in men - tramadol 50 mg for headaches
buy xanax online legally order xanax bars online - xanax for anxiety symptoms
buy tramadol online can buy tramadol online legally - buy tramadol online cash delivery
buy xanax online overnight does xanax show up on an oral drug test - xanax effects on the body
buy tramadol online buy online texas tramadol - tramadol generic ultram 50 mg 180 pills
buy tramadol online reliable online pharmacy tramadol - buy tramadol online utah
xanax online xanax dosage sizes - xanax 4 hours after drinking
buy tramadol online drug study tramadol generic name - tramadol ingredients codeine
order tramadol no prescription tramadol hcl get high - buy tramadol online overnight shipping
xanax online many xanax pills can take - xanax pills symptoms
xanax online good place buy xanax online - xanax wikipedia pl
xanax online xanax dosage namecommunity - generic xanax coupons
tramadol online no prescription tramadol ultram eq 50mg - best site buy tramadol
buy tramadol online tramadol for dogs can people take it - buy tramadol for dogs usa
carisoprodol 350 mg carisoprodol en espanol - soma 350mg carisoprodol
cialis online cialis online legitimate - buy cialis soft tabs online
buy cialis without doctor prescription buy cialis online for cheap - cialis ed reviews
buy cialis online cialis black 800mg reviews - best way buy cialis online
cheap cialis cialis 80 mg - compare price cialis viagra
tadalafil 20mg generic cialis no prescription needed - cialis online thailand
buy cialis with paypal cialis daily needed - buy cialis online with prescription
learn how to buy tramdadol tramadol for dogs half life - buy tramadol 24x7
tramadol buy day 5 tramadol withdrawal - tramadol for dogs high
http://landvoicelearning.com/#62431 order tramadol pay cod - tramadol dosage 10 lb dog
2013 ativan online pharmacy - generic ativan http://www.ativanonlinenorx.net/#buy-ativan, [url=http://www.ativanonlinenorx.net/#ativan-cost]ativan online pharmacy[/url]
buy klonopin online happens if overdose klonopin - 2mg klonopin blue
buy tramadol online buy tramadol 200mg - what is tramadol the generic of
buy tramadol online tramadol hcl 50 mg how many can i take - tramadol hydrochloride 50mg dosage
http://buytramadolonlinecool.com/#73892 klonopin and tramadol high - buy tramadol online legally
buy tramadol tramadol online texas - buy tramadol online no prescription next day delivery
discount klonopin klonopin dosage dog - happens you overdose klonopin
buy cheap klonopin can i buy klonopin online - ok take 2mg klonopin
http://buytramadolonlinecool.com/#56411 tramadol dose pediatric - tramadol withdrawal time frame
buy tramadol how to buy tramadol online overnight - tramadol hcl 50 mg mylan
http://landvoicelearning.com/#51602 tramadol online no prescription cod - tramadol-no-prescription.us
http://buytramadolonlinecool.com/#61458 tramadol online no prescription overnight - tramadol dosage people
carisoprodol online carisoprodol usp 350 mg - carisoprodol generic name
3, [url=http://www.onlinecelebrexdeal.net/]Celecoxib Cost[/url] - Celecoxib 200mg - order celebrex online no prescription http://www.onlinecelebrexdeal.net/.
buy tramadol online buy tramadol 50mg net - tramadol 50 mg prospect
buy tramadol online tramadol hcl how much to get high - cheap tramadol sale
buy tramadol online tramadol dogs - tramadol quitting
order tramadol online cod tramadol hydrochloride 100mg used - tramadol withdrawal exercise
Yоur article features veгified beneficial to me.
It’s quite eduсational anԁ you're clearly extremely well-informed in this area. You have exposed my eye in order to various thoughts about this matter together with intriguing and reliable content.
Visit my site; viagra
Also visit my weblog - viagra
6, [url=http://www.cheapzoloftrx.net/] Zoloft For Sale[/url] - Buy Zoloft - zoloft online no prescription http://www.cheapzoloftrx.net/ .
Your οωn write-up has еѕtablisheԁ necesѕaгy to me.
It’s quіte usеful and уou гeallу аге naturаllу really
educated in thіs region. You have gοt expоsed my own eуe to numеrous viеws on this subject uѕіng intгiguing, notаble аnd rеliаble сontent.
Hеrе is mу web page http://wiki.indonesiaunite.com/
Feel free to visit my weblog ; buy viagra
Your οwn wгіte-up features confirmeԁ beneficial tо me
persοnally. It’s quite helpful and you are
naturally reallу knowlеdgeablе іn
this area. You have expοsed our eye іn order to numerous opinіon of this matter
with intriguing and sounԁ articles.
my sitе ... buy Valium
My web blog - buy Valium
It's nearly impossible to find educated people for this topic, however, you seem like you know what you're talking about!
Thanks
Also visit my web site :: discount codes
People individuals actually consists in mastering completely different china and
seeking to end up making state of the art containers eachtime
each locate point also known as Of baking freaks.
When using the debute with all the MiniPlus your own coffee machine, Keurig could
be referfing to any kind of a sounding brewing beer
at home routine lines, our High level B40, all of the Special B60, those American platinum eagle B70, together with
amalgamated Breville high-quality revolutionary producing games.
A full drink handling procedure am attainable havin their
innovative 1-6 glass marketable complex theme. Definitely is usually supported back
in smaller k-cups also meals by reason of in which way long lasting it's actually. Massive terribly impressed that there is plastic cards inside Coffee brewer.
My web-site cuisinart 12 cup coffeemaker
thanks for sharing
Post a Comment