本文整理匯總了Java中org.apache.activemq.ActiveMQConnection.DEFAULT_PASSWORD屬性的典型用法代碼示例。如果您正苦於以下問題:Java ActiveMQConnection.DEFAULT_PASSWORD屬性的具體用法?Java ActiveMQConnection.DEFAULT_PASSWORD怎麽用?Java ActiveMQConnection.DEFAULT_PASSWORD使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.activemq.ActiveMQConnection
的用法示例。
在下文中一共展示了ActiveMQConnection.DEFAULT_PASSWORD屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Sender
/**
*
* @param queue_name : name of destination message queue
* @param host_name : destination ip/host name
*/
public Sender(String queue_name, String host_name) {
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://" + host_name +":61616");
try {
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(Boolean.TRUE,
Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue(queue_name);
producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
} catch (JMSException je) {
je.printStackTrace();
}
}
示例2: Receiver
public Receiver(String queue_name) {
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(Boolean.FALSE,
Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue(queue_name);
consumer = session.createConsumer(destination);
} catch(JMSException je) {
je.printStackTrace();
}
}
示例3: init
@Override
public void init(Config config) throws TestException {
super.init(config);
String providerUrl = config.getPropertyValue("providerUrl");
String destinationType = config.getPropertyValue("destinationType");
String destinationName = config.getPropertyValue("destinationName");
if (providerUrl == null) {
throw new TestException("providerUrl property must be specified");
}
if (destinationType == null) {
throw new TestException("destinationType property must be specified");
}
if (!(destinationType.equals("Queue") || destinationType.equals("Topic"))) {
throw new TestException("destinationType property must be 'Queue' or 'Topic'");
}
if (destinationName == null) {
throw new TestException("destinationName property must be specified");
}
try {
String userName = ActiveMQConnection.DEFAULT_USER;
String password = ActiveMQConnection.DEFAULT_PASSWORD;
String tuning = "?tcpNoDelay=true&socketBufferSize=65536&wireFormat.tcpNoDelayEnabled=true&wireFormat.cacheEnabled=true&wireFormat.cacheSize=1024&wireFormat.tightEncodingEnabled=true";
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(userName, password, providerUrl + tuning);
connection = factory.createConnection();
connection.start();
boolean transacted = false;
session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
Destination destination = (destinationType.equals("Queue")) ? session.createQueue(destinationName) : session.createTopic(destinationName);
producer = session.createProducer(destination);
} catch (JMSException error) {
throw new TestException(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage()), error);
}
}
示例4: init
@Override
public void init(Config config) throws TestException {
super.init(config);
String providerUrl = config.getPropertyValue("providerUrl");
String destinationType = config.getPropertyValue("destinationType");
String destinationName = config.getPropertyValue("destinationName");
if (providerUrl == null) {
throw new TestException("providerUrl property must be specified");
}
if (destinationType == null) {
throw new TestException("destinationType property must be specified");
}
if (!(destinationType.equals("Queue") || destinationType.equals("Topic"))) {
throw new TestException("destinationType property must be 'Queue' or 'Topic'");
}
if (destinationName == null) {
throw new TestException("destinationName property must be specified");
}
try {
String userName = ActiveMQConnection.DEFAULT_USER;
String password = ActiveMQConnection.DEFAULT_PASSWORD;
String tuning = "?tcpNoDelay=true&socketBufferSize=65536&wireFormat.tcpNoDelayEnabled=true&wireFormat.cacheEnabled=true&wireFormat.cacheSize=1024&wireFormat.tightEncodingEnabled=true";
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
userName, password, providerUrl + tuning);
connection = factory.createConnection();
connection.start();
boolean transacted = false;
session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
Destination destination = (destinationType.equals("Queue")) ? session.createQueue(destinationName) : session.createTopic(destinationName);
consumer = session.createConsumer(destination);
} catch (JMSException error) {
throw new TestException(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage()), error);
}
}
示例5: main
public static void main(String[] args) throws JMSException {
// 通過username,password,url創建連接工廠接口
ConnectionFactory factory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD, "tcp://localhost:61616");
// 通過連接工廠創建一個新的連接接口
Connection connection = factory.createConnection();
// 通過連接接口創建一個會話接口
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// 會話接口創建有關主題的目標接口
Destination destination = session.createQueue("queue_test");
// 會話接口再根據目標接口來創建一個消息生產者接口
MessageProducer producer = session.createProducer(destination);
//設置消息生存時間,超過該時間,消息會被移除,不設置永久
// producer.setTimeToLive(60000);
//設置消息優先級0~9個級別,0最低,9最高
producer.setPriority(5);
//設置消息持久性:DeliveryMode.PERSISTENT,DeliveryMode.NON_PERSISTENT,默認為PERSISTENT
//持久性消息隻被傳輸一次,非持久性消息最多被傳輸一次,有可能是0次,比如,JMS提供者故障時消息被丟失的時候
//可以分別測試設置PERSISTENT和NON_PERSISTENT,當關閉JMS重新啟動
// producer.setDeliveryMode(DeliveryMode.PERSISTENT);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// 調用會話生成一個文本消息
Message message = session.createTextMessage("Hello World!");
//設置消息選擇器,當有多個應用都需要從同一個隊列取消息的時候,可以通過指定消息選擇器,來進行消息過濾
//消息頭中的可以使用選擇器的屬性:JMSDeliveryMode、JMSPriority、JMSMessageID、JMSTimestamp、JMSCorrelationID、JMSType
//這裏使用JMSCorrelationID來指定消息選擇器,消息的接收者在創建的時候需要指定
//MessageConsumer consumer = session.createConsumer(dest, "JMSMessageID ='123456789'");
//使用producer.setDeliveryMode
// message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
//設置消息優先級0~9個級別,0最低,9最高,如果設置了producer.setPriority,則優先級以producer設置的為準
message.setJMSPriority(4);
//設置消息時間戳
message.setJMSTimestamp(System.currentTimeMillis());
//設置消息過期時間,如果設置為0標示永不過期,使用上麵的方法:producer.setTimeToLive
// message.setJMSExpiration(5);
//設置消息類型
message.setJMSType("TEST");
//設置消息惟一標識,隻能在消息發送後才能確定
//message.setJMSMessageID("123456789");
//設置消息返回時發送給指定目標Destination
message.setJMSReplyTo(session.createQueue("queue_test_replay"));
// 通過生產者接口Send將消息發布到ActiveMQ服務器
producer.send(message);
//消息發送後獲取的JMSMessageID和自己指定的不一樣,這是自動生成的
System.out.println(message.getJMSMessageID());
// 關閉會話
session.close();
// 關閉連接
connection.close();
}
示例6: main
public static void main(String[] args) throws JMSException {
// 通過username,password,url創建連接工廠接口
ConnectionFactory factory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD, "tcp://localhost:61616");
// 通過連接工廠創建一個新的連接接口
Connection connection = factory.createConnection();
connection.start();
// 通過連接接口創建一個會話接口
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// 會話接口創建有關主題的目標接口
Destination destination = session.createQueue("queue_test_replay");
// 會話接口再根據目標接口來創建一個消息消費者接口
MessageConsumer consumer = session.createConsumer(destination);
//指定消息選擇器,隻接收指定選擇器的消息,表達式符合SQL語法,發送消息的時候需要設置選擇器值
// MessageConsumer consumer = session.createConsumer(destination, "JMSCorrelationID ='123456789'");
//同步接收消息:隻能接收一次消息
// 1.阻塞等待消息,直到收到信息才返回
// TextMessage message = (TextMessage) consumer.receive();
// 2.阻塞等待消息,超出指定超時時間或收到信息就不等待
// TextMessage message = (TextMessage) consumer.receive(3000);
// 3. 不阻塞等待消息,有消息直接返回,無消息返回null
// TextMessage message = (TextMessage) consumer.receiveNoWait();
// if (null != message) {
// System.out.println("收到消息:" + message.getText());
// Destination replyDdestination = message.getJMSReplyTo();
// //創建一個新的MessageProducer來發送一個回複消息。
// MessageProducer producer = session.createProducer(replyDdestination);
// producer.send(session.createTextMessage("Hello " + message.getText()));
//
// } else {
// System.out.println("沒有收到消息!");
// }
//
//異步消息,使用監聽器來接收消息,當有消息的時候,會自動調用onMessage方法,可以多次接收消息,確保Session不要關閉
consumer.setMessageListener(new MessageListener() {
public void onMessage(Message message) {
// 消息消費者接收消息
if (null != message) {
try {
System.out.println("收到replay消息:" + ((TextMessage) message).getText());
} catch (JMSException e) {
e.printStackTrace();
}
} else {
System.out.println("沒有收到消息!");
}
}
});
// 關閉會話,設置監聽消息的時候不要關閉
// session.close();
// 關閉連接,設置監聽消息的時候不要關閉
// connection.close();
}
示例7: main
public static void main(String[] args) throws JMSException {
// 通過username,password,url創建連接工廠接口
ConnectionFactory factory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD, "tcp://localhost:61616");
// 通過連接工廠創建一個新的連接接口
Connection connection = factory.createConnection();
connection.start();
// 通過連接接口創建一個會話接口
final Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// 會話接口創建有關主題的目標接口
Destination destination = session.createQueue("queue_test");
// Destination destination = session.createQueue("queue_test_replay");
// 會話接口再根據目標接口來創建一個消息消費者接口
MessageConsumer consumer = session.createConsumer(destination);
//指定消息選擇器,隻接收指定選擇器的消息,表達式符合SQL語法,發送消息的時候需要設置選擇器值
// MessageConsumer consumer = session.createConsumer(destination, "JMSCorrelationID ='123456789'");
//同步接收消息:隻能接收一次消息
// 1.阻塞等待消息,直到收到信息才返回
// TextMessage message = (TextMessage) consumer.receive();
// 2.阻塞等待消息,超出指定超時時間或收到信息就不等待
// TextMessage message = (TextMessage) consumer.receive(3000);
// 3. 不阻塞等待消息,有消息直接返回,無消息返回null
// TextMessage message = (TextMessage) consumer.receiveNoWait();
// if (null != message) {
// System.out.println("收到消息:" + message.getText());
// } else {
// System.out.println("沒有收到消息!");
// }
//異步消息,使用監聽器來接收消息,當有消息的時候,會自動調用onMessage方法,可以多次接收消息,確保Session不要關閉
consumer.setMessageListener(new MessageListener() {
public void onMessage(Message message) {
// 消息消費者接收消息
if (null != message) {
try {
String msg = ((TextMessage) message).getText();
System.out.println("收到消息:" + msg);
//根據JMSReplyTo獲取返回Destination
Destination replyDdestination = message.getJMSReplyTo();
//創建一個新的MessageProducer來發送一個回複消息。
MessageProducer producer = session.createProducer(replyDdestination);
producer.send(session.createTextMessage("Hello " + msg));
} catch (JMSException e) {
e.printStackTrace();
}
} else {
System.out.println("沒有收到消息!");
}
}
});
// 關閉會話,設置監聽消息的時候不要關閉
// session.close();
// 關閉連接,設置監聽消息的時候不要關閉
// connection.close();
}
示例8: main
public static void main(String[] args) {
// ConnectionFactory :連接工廠,JMS 用它創建連接
ConnectionFactory connectionFactory;
// Connection :JMS 客戶端到JMS Provider 的連接
Connection connection = null;
// Session: 一個發送或接收消息的線程
Session session;
// Destination :消息的目的地;消息發送給誰.
Destination destination;
// MessageProducer:消息發送者
MessageProducer producer;
// TextMessage message;
// 構造ConnectionFactory實例對象,此處采用ActiveMq的實現jar
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
// 構造從工廠得到連接對象
connection = connectionFactory.createConnection();
// 啟動
connection.start();
// 獲取操作連接
session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
// 獲取session注意參數值xingbo.xu-queue是一個服務器的queue,須在在ActiveMq的console配置
destination = session.createQueue("queue1");
// 得到消息生成者【發送者】
producer = session.createProducer(destination);
// 設置不持久化,此處學習,實際根據項目決定
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// 構造消息,此處寫死,項目就是參數,或者方法獲取
sendMessage(session, producer);
session.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}
示例9: main
public static void main(String[] args) {
// ConnectionFactory :連接工廠,JMS 用它創建連接
ConnectionFactory connectionFactory;
// Connection :JMS 客戶端到JMS Provider 的連接
Connection connection = null;
// Session: 一個發送或接收消息的線程
Session session;
// Destination :消息的目的地;消息發送給誰.
Destination destination;
// 消費者,消息接收者
MessageConsumer consumer;
connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, "tcp://localhost:61616");
try {
// 構造從工廠得到連接對象
connection = connectionFactory.createConnection();
// 啟動
connection.start();
// 獲取操作連接
session = connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
// 獲取session注意參數值xingbo.xu-queue是一個服務器的queue,須在在ActiveMq的console配置
destination = session.createQueue("queue1");
consumer = session.createConsumer(destination);
while (true) {
// 設置接收者接收消息的時間,為了便於測試,這裏誰定為100s
TextMessage message = (TextMessage) consumer.receive(100000);
if (null != message) {
System.out.println("收到消息" + message.getText());
} else {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}
示例10: main
public static void main(String[] args) {
// ConnectionFactory :連接工廠,JMS 用它創建連接
ConnectionFactory connectionFactory;
// Connection :JMS 客戶端到JMS Provider 的連接
Connection connection = null;
// Session: 一個發送或接收消息的線程
Session session;
// Destination :消息的目的地;消息發送給誰.
Destination destination;
// MessageProducer:消息發送者
MessageProducer producer;
// TextMessage message;
// 構造ConnectionFactory實例對象,此處采用ActiveMq的實現jar
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
// 構造從工廠得到連接對象
connection = connectionFactory.createConnection();
// 啟動
connection.start();
// 獲取操作連接
session = connection.createSession(Boolean.TRUE,
Session.AUTO_ACKNOWLEDGE);
// 獲取session注意參數值xingbo.xu-queue是一個服務器的queue,須在在ActiveMq的console配置
destination = session.createQueue("FirstQueue");
// 得到消息生成者【發送者】
producer = session.createProducer(destination);
// 設置不持久化,此處學習,實際根據項目決定
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// 構造消息,此處寫死,項目就是參數,或者方法獲取
sendMessage(session, producer);
session.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}
示例11: main
public static void main(String[] args) {
// ConnectionFactory :連接工廠,JMS 用它創建連接
ConnectionFactory connectionFactory;
// Connection :JMS 客戶端到JMS Provider 的連接
Connection connection = null;
// Session: 一個發送或接收消息的線程
Session session;
// Destination :消息的目的地;消息發送給誰.
Destination destination;
// 消費者,消息接收者
MessageConsumer consumer;
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
// 構造從工廠得到連接對象
connection = connectionFactory.createConnection();
// 啟動
connection.start();
// 獲取操作連接
session = connection.createSession(Boolean.FALSE,
Session.AUTO_ACKNOWLEDGE);
// 獲取session注意參數值xingbo.xu-queue是一個服務器的queue,須在在ActiveMq的console配置
destination = session.createQueue("FirstQueue");
consumer = session.createConsumer(destination);
while (true) {
//設置接收者接收消息的時間,為了便於測試,這裏誰定為100s
TextMessage message = (TextMessage) consumer.receive(100000);
if (null != message) {
System.out.println("收到消息" + message.getText());
} else {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}
示例12: main
public static void main(String[] args) {
// ConnectionFactory :連接工廠,JMS 用它創建連接
ConnectionFactory connectionFactory;
// Connection :JMS 客戶端到JMS Provider 的連接
Connection connection = null;
// Session: 一個發送或接收消息的線程
Session session;
// Destination :消息的目的地;消息發送給誰.
Destination destination;
// MessageProducer:消息發送者
MessageProducer producer;
// TextMessage message;
// 構造ConnectionFactory實例對象,此處采用ActiveMq的實現jar
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
// 構造從工廠得到連接對象
connection = connectionFactory.createConnection();
// 啟動
connection.start();
// 獲取操作連接
session = connection.createSession(Boolean.TRUE,
Session.AUTO_ACKNOWLEDGE);
// 獲取session注意參數值xingbo.xu-queue是一個服務器的queue,須在在ActiveMq的console配置
destination = session.createQueue("FirstQueue");
// 得到消息生成者【發送者】
producer = session.createProducer(destination);
// 設置不持久化,此處學習,實際根據項目決定
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// 構造消息,此處寫死,項目就是參數,或者方法獲取
sendMessage(session, producer);
session.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}
示例13: main
public static void main(String[] args) {
// ConnectionFactory :連接工廠,JMS 用它創建連接
ConnectionFactory connectionFactory;
// Connection :JMS 客戶端到JMS Provider 的連接
Connection connection = null;
// Session: 一個發送或接收消息的線程
Session session;
// Destination :消息的目的地;消息發送給誰.
Destination destination;
// 消費者,消息接收者
MessageConsumer consumer;
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
// 構造從工廠得到連接對象
connection = connectionFactory.createConnection();
// 啟動
connection.start();
// 獲取操作連接
session = connection.createSession(Boolean.FALSE,
Session.AUTO_ACKNOWLEDGE);
// 獲取session注意參數值xingbo.xu-queue是一個服務器的queue,須在在ActiveMq的console配置
destination = session.createQueue("FirstQueue");
consumer = session.createConsumer(destination);
while (true) {
//設置接收者接收消息的時間,為了便於測試,這裏誰定為100s
TextMessage message = (TextMessage) consumer.receive(100000);
if (null != message) {
System.out.println("收到消息" + message.getText());
} else {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}