當前位置: 首頁>>代碼示例>>Java>>正文


Java ActiveMQConnection類代碼示例

本文整理匯總了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);
  }
 
開發者ID:ClearPointNZ,項目名稱:connect-sample-apps,代碼行數:24,代碼來源:Publisher.java

示例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();
       } 

}
 
開發者ID:knshen,項目名稱:JSearcher,代碼行數:26,代碼來源:Sender.java

示例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();
	}
}
 
開發者ID:knshen,項目名稱:JSearcher,代碼行數:18,代碼來源:Receiver.java

示例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();
}
 
開發者ID:bptlab,項目名稱:Unicorn,代碼行數:30,代碼來源:JMSProvider.java

示例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();
}
 
開發者ID:bptlab,項目名稱:Unicorn,代碼行數:20,代碼來源:JMSProvider.java

示例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();
  }
}
 
開發者ID:techysoul,項目名稱:java,代碼行數:17,代碼來源:DeliveryCheckSpout.java

示例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();
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:22,代碼來源:MessageCompressionTest.java

示例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());
            }
        }
    }
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:19,代碼來源:ActiveMQMessage.java

示例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);
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:21,代碼來源:ActiveMQMapMessage.java

示例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);
        }
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:25,代碼來源:ActiveMQObjectMessage.java

示例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();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:23,代碼來源:BasicOpenWireTest.java

示例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();
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:22,代碼來源:MessageCompressionTest.java

示例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();
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:ProducerFlowControlTest.java

示例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));
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:17,代碼來源:ProducerFlowControlTest.java

示例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());
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:CompressionOverNetworkTest.java


注:本文中的org.apache.activemq.ActiveMQConnection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。