本文整理匯總了Java中org.apache.activemq.ActiveMQConnection類的典型用法代碼示例。如果您正苦於以下問題:Java ActiveMQConnection類的具體用法?Java ActiveMQConnection怎麽用?Java ActiveMQConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ActiveMQConnection類屬於org.apache.activemq包,在下文中一共展示了ActiveMQConnection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
public void create(String clientId, String topicName) throws JMSException {
this.clientId = clientId;
String brokerUrl = System.getProperty("activemq.brokerurl", ActiveMQConnection.DEFAULT_BROKER_URL);
log.info("Got brokerurl: " + brokerUrl);
// create a Connection Factory
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
// create a Connection
connection = connectionFactory.createConnection();
connection.setClientID(clientId);
// create a Session
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// create the Topic to which messages will be sent
Topic topic = session.createTopic(topicName);
// create a MessageProducer for sending messages
messageProducer = session.createProducer(topic);
}
示例2: Sender
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
/**
*
* @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();
}
}
示例3: Receiver
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
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();
}
}
示例4: destroyMessageQueue
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
/**
* Queues are created dynamically, but can must be destroyed explicitly by
* calling this method. Queues with active subscribers cannot be destroyed
* and result in an exception.
*
* @param brokerHost
* @param brokerPort
* @param topic
* @throws JMSException
*/
public static void destroyMessageQueue(final String brokerHost, final String brokerPort, final String topic) throws JMSException {
// Create a ConnectionFactory
final ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(String.format("tcp://%s:%s", brokerHost, brokerPort));
// Create a Connection
final Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue), close Handle after that
final Destination destination = session.createQueue(topic);
session.close();
// Destroy Empty Queue And Clean Up
((ActiveMQConnection) connection).destroyDestination((ActiveMQDestination) destination);
connection.close();
}
示例5: destroyMessageQueue
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
public static void destroyMessageQueue(String brokerHost, String brokerPort, String topic) throws JMSException {
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(String.format("tcp://%s:%s", brokerHost, brokerPort));
// 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(topic);
session.close();
// Destroy Empty Queue
((ActiveMQConnection) connection).destroyDestination((ActiveMQDestination) destination);
connection.close();
}
示例6: setConnection
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
private void setConnection(String clientid) {
ConnectionFactory connectionFactory =
new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
try {
connection = connectionFactory.createConnection();
if (clientid != null)
connection.setClientID(clientid);
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: sendTestStreamMessage
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
private void sendTestStreamMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
StreamMessage streamMessage = session.createStreamMessage();
streamMessage.writeBoolean(true);
streamMessage.writeByte((byte) 10);
streamMessage.writeBytes(TEXT.getBytes());
streamMessage.writeChar('A');
streamMessage.writeDouble(55.3D);
streamMessage.writeFloat(79.1F);
streamMessage.writeInt(37);
streamMessage.writeLong(56652L);
streamMessage.writeObject(new String("VVVV"));
streamMessage.writeShort((short) 333);
streamMessage.writeString(TEXT);
producer.send(streamMessage);
connection.close();
}
示例8: checkValidObject
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
protected void checkValidObject(Object value) throws MessageFormatException {
boolean valid = value instanceof Boolean || value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long;
valid = valid || value instanceof Float || value instanceof Double || value instanceof Character || value instanceof String || value == null;
if (!valid) {
ActiveMQConnection conn = getConnection();
// conn is null if we are in the broker rather than a JMS client
if (conn == null || conn.isNestedMapAndListEnabled()) {
if (!(value instanceof Map || value instanceof List)) {
throw new MessageFormatException("Only objectified primitive objects, String, Map and List types are allowed but was: " + value + " type: " + value.getClass());
}
} else {
throw new MessageFormatException("Only objectified primitive objects and String types are allowed but was: " + value + " type: " + value.getClass());
}
}
}
示例9: storeContent
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
@Override
public void storeContent() {
try {
if (getContent() == null && !map.isEmpty()) {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
ActiveMQConnection connection = getConnection();
if (connection != null && connection.isUseCompression()) {
compressed = true;
os = new DeflaterOutputStream(os);
}
DataOutputStream dataOut = new DataOutputStream(os);
MarshallingSupport.marshalPrimitiveMap(map, dataOut);
dataOut.close();
setContent(bytesOut.toByteSequence());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例10: storeContent
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
@Override
public void storeContent() {
ByteSequence bodyAsBytes = getContent();
if (bodyAsBytes == null && object != null) {
try {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
ActiveMQConnection connection = getConnection();
if (connection != null && connection.isUseCompression()) {
compressed = true;
os = new DeflaterOutputStream(os);
}
DataOutputStream dataOut = new DataOutputStream(os);
ObjectOutputStream objOut = new ObjectOutputStream(dataOut);
objOut.writeObject(object);
objOut.flush();
objOut.reset();
objOut.close();
setContent(bytesOut.toByteSequence());
} catch (IOException ioe) {
throw new RuntimeException(ioe.getMessage(), ioe);
}
}
}
示例11: setUp
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
@Override
@Before
public void setUp() throws Exception {
super.setUp();
System.setProperty("org.apache.activemq.transport.AbstractInactivityMonitor.keepAliveTime", "5");
createFactories();
SimpleString coreQueue = new SimpleString(queueName);
this.server.createQueue(coreQueue, RoutingType.ANYCAST, coreQueue, null, false, false, -1, false, true);
testQueues.put(queueName, coreQueue);
SimpleString coreQueue2 = new SimpleString(queueName2);
this.server.createQueue(coreQueue2, RoutingType.ANYCAST, coreQueue2, null, false, false, -1, false, true);
testQueues.put(queueName2, coreQueue2);
SimpleString durableQueue = new SimpleString(durableQueueName);
this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
testQueues.put(durableQueueName, durableQueue);
if (!enableSecurity) {
connection = (ActiveMQConnection) factory.createConnection();
}
}
示例12: sendTestMapMessage
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
private void sendTestMapMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
MapMessage mapMessage = session.createMapMessage();
mapMessage.setBoolean("boolean-type", true);
mapMessage.setByte("byte-type", (byte) 10);
mapMessage.setBytes("bytes-type", TEXT.getBytes());
mapMessage.setChar("char-type", 'A');
mapMessage.setDouble("double-type", 55.3D);
mapMessage.setFloat("float-type", 79.1F);
mapMessage.setInt("int-type", 37);
mapMessage.setLong("long-type", 56652L);
mapMessage.setObject("object-type", new String("VVVV"));
mapMessage.setShort("short-type", (short) 333);
mapMessage.setString("string-type", TEXT);
producer.send(mapMessage);
connection.close();
}
示例13: testSimpleSendReceive
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
@Test
public void testSimpleSendReceive() throws Exception {
factory.setAlwaysSyncSend(true);
flowControlConnection = (ActiveMQConnection) factory.createConnection();
flowControlConnection.start();
Session session = flowControlConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(queueA);
// Test sending to Queue B it should not block.
CountDownLatch pubishDoneToQeueuA = asyncSendTo(queueA, "Message 1");
assertTrue(pubishDoneToQeueuA.await(2, TimeUnit.SECONDS));
TextMessage msg = (TextMessage) consumer.receive();
assertEquals("Message 1", msg.getText());
msg.acknowledge();
pubishDoneToQeueuA = asyncSendTo(queueA, "Message 2");
assertTrue(pubishDoneToQeueuA.await(2, TimeUnit.SECONDS));
msg = (TextMessage) consumer.receive();
assertEquals("Message 2", msg.getText());
msg.acknowledge();
consumer.close();
}
示例14: test2ndPublisherWithStandardConnectionThatIsBlocked
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
@Test
public void test2ndPublisherWithStandardConnectionThatIsBlocked() throws Exception {
flowControlConnection = (ActiveMQConnection) factory.createConnection();
flowControlConnection.start();
// Test sending to Queue A
// 1st send should not block.
fillQueue(queueA);
// Test sending to Queue B it should block.
// Since even though the it's queue limits have not been reached, the
// connection
// is blocked.
CountDownLatch pubishDoneToQeueuB = asyncSendTo(queueB, "Message 1");
assertFalse(pubishDoneToQeueuB.await(2, TimeUnit.SECONDS));
}
示例15: testCompressedOverCompressedNetwork
import org.apache.activemq.ActiveMQConnection; //導入依賴的package包/類
@Test
public void testCompressedOverCompressedNetwork() throws Exception {
ActiveMQConnection localAmqConnection = (ActiveMQConnection) localConnection;
localAmqConnection.setUseCompression(true);
MessageConsumer consumer1 = remoteSession.createConsumer(included);
MessageProducer producer = localSession.createProducer(included);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
waitForConsumerRegistration(localBroker, 1, included);
StringBuilder payload = new StringBuilder("test-");
for (int i = 0; i < 100; ++i) {
payload.append(UUID.randomUUID().toString());
}
Message test = localSession.createTextMessage(payload.toString());
producer.send(test);
Message msg = consumer1.receive(RECEIVE_TIMEOUT_MILLS);
assertNotNull(msg);
ActiveMQTextMessage message = (ActiveMQTextMessage) msg;
assertTrue(message.isCompressed());
assertEquals(payload.toString(), message.getText());
}