JMS 메시지 큐 ActiveMQ (점 대 점 모드)
package com.java1234.activemq;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
/**
*
* @author Administrator
*
*/
public class JMSProducer {
private static final String USERNAME=ActiveMQConnection.DEFAULT_USER; //
private static final String PASSWORD=ActiveMQConnection.DEFAULT_PASSWORD; //
private static final String BROKEURL=ActiveMQConnection.DEFAULT_BROKER_URL; //
private static final int SENDNUM=10; //
public static void main(String[] args) {
ConnectionFactory connectionFactory; //
Connection connection = null; //
Session session; //
Destination destination; //
MessageProducer messageProducer; //
//
connectionFactory=new ActiveMQConnectionFactory(JMSProducer.USERNAME, JMSProducer.PASSWORD, JMSProducer.BROKEURL);
try {
connection=connectionFactory.createConnection(); //
connection.start(); //
session=connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE); // Session
destination=session.createQueue("FirstQueue1"); //
messageProducer=session.createProducer(destination); //
sendMessage(session, messageProducer); //
session.commit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(connection!=null){
try {
connection.close();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/**
*
* @param session
* @param messageProducer
* @throws Exception
*/
public static void sendMessage(Session session,MessageProducer messageProducer)throws Exception{
for(int i=0;i
(Consumer)--( )->
package com.java1234.activemq;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
/**
*
* @author Administrator
*
*/
public class JMSConsumer2 {
private static final String USERNAME=ActiveMQConnection.DEFAULT_USER; //
private static final String PASSWORD=ActiveMQConnection.DEFAULT_PASSWORD; //
private static final String BROKEURL=ActiveMQConnection.DEFAULT_BROKER_URL; //
public static void main(String[] args) {
ConnectionFactory connectionFactory; //
Connection connection = null; //
Session session; //
Destination destination; //
MessageConsumer messageConsumer; //
//
connectionFactory=new ActiveMQConnectionFactory(JMSConsumer2.USERNAME, JMSConsumer2.PASSWORD, JMSConsumer2.BROKEURL);
try {
connection=connectionFactory.createConnection(); //
connection.start(); //
session=connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE); // Session
destination=session.createQueue("FirstQueue1"); //
messageConsumer=session.createConsumer(destination); //
messageConsumer.setMessageListener(new Listener()); //
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
감청 (Listener) 메시지 큐package com.java1234.activemq;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
/**
*
* @author Administrator
*
*/
public class Listener implements MessageListener{
@Override
public void onMessage(Message message) {
// TODO Auto-generated method stub
try {
System.out.println(" :"+((TextMessage)message).getText());
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
glassfish+mdb+activeMQ자세히 보기 1. active 콘솔에 새로운queue:batchAdjust 2.glassfish의 구성 스크립트를 스크립트로 설정하면 다음과 같습니다. 2. 그리고 netbean6.1로 생성된 MDB에 빨간색 부분을...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.