Package org.apache.activemq

Examples of org.apache.activemq.ActiveMQConnection


        assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", compressedSize < unCompressedSize);
    }

    private void sendTestMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
        ActiveMQConnection connection = (ActiveMQConnection)factory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        producer.send(session.createTextMessage(message));
        connection.close();
    }
View Full Code Here


        producer.send(session.createTextMessage(message));
        connection.close();
    }

    private ActiveMQTextMessage receiveTestMessage(ActiveMQConnectionFactory factory) throws JMSException {
        ActiveMQConnection connection = (ActiveMQConnection)factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(queue);
        ActiveMQTextMessage rc = (ActiveMQTextMessage)consumer.receive();
        connection.close();
        return rc;
    }
View Full Code Here

        connection.close();
        return rc;
    }

    private void sendTestBytesMessage(ActiveMQConnectionFactory factory, String message) throws JMSException, UnsupportedEncodingException {
        ActiveMQConnection connection = (ActiveMQConnection)factory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        BytesMessage bytesMessage = session.createBytesMessage();
        bytesMessage.writeBytes(message.getBytes("UTF8"));
        producer.send(bytesMessage);
        connection.close();
    }
View Full Code Here

        producer.send(bytesMessage);
        connection.close();
    }

    private ActiveMQBytesMessage receiveTestBytesMessage(ActiveMQConnectionFactory factory) throws JMSException, UnsupportedEncodingException {
        ActiveMQConnection connection = (ActiveMQConnection)factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(queue);
        ActiveMQBytesMessage rc = (ActiveMQBytesMessage)consumer.receive();
        connection.close();
        return rc;
    }
View Full Code Here

        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());
View Full Code Here

    private 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);
View Full Code Here

       * Test the case where the broker is blocked due to a memory limit
       * and a producer timeout is set on the connection.
       * @throws Exception
       */
      public void testBlockedProducerConnectionTimeout() throws Exception {
          final ActiveMQConnection cx = (ActiveMQConnection)createConnection();
          final ActiveMQDestination queue = createDestination("testqueue");
         
          // we should not take longer than 10 seconds to return from send
          cx.setSendTimeout(10000);
           
          Runnable r = new Runnable() {
              public void run() {
                  try {
                    LOG.info("Sender thread starting");
                      Session session = cx.createSession(false, 1);
                      MessageProducer producer = session.createProducer(queue);
                      producer.setDeliveryMode(DeliveryMode.PERSISTENT);
                     
                      TextMessage message = session.createTextMessage(createMessageText());
                      for(int count=0; count<messageCount; count++){
                        producer.send(message);
                      }   
                      LOG.info("Done sending..");
                    } catch (JMSException e) {
                        if (e.getCause() instanceof RequestTimedOutIOException) {
                          exceptionCount.incrementAndGet();
                        } else {
                            e.printStackTrace();
                        }
                      return;
                  }

              }
          };
          cx.start();
          Thread producerThread = new Thread(r);
          producerThread.start();
          producerThread.join(30000);
          cx.close();
          // We should have a few timeout exceptions as memory store will fill up
          assertTrue("No exception from the broker", exceptionCount.get() > 0);
      }
View Full Code Here

       * Test the case where the broker is blocked due to a memory limit
       * with a fail timeout
       * @throws Exception
       */
      public void testBlockedProducerUsageSendFailTimeout() throws Exception {
          final ActiveMQConnection cx = (ActiveMQConnection)createConnection();
          final ActiveMQDestination queue = createDestination("testqueue");

            broker.getSystemUsage().setSendFailIfNoSpaceAfterTimeout(5000);
          Runnable r = new Runnable() {
              public void run() {
                  try {
                    LOG.info("Sender thread starting");
                      Session session = cx.createSession(false, 1);
                      MessageProducer producer = session.createProducer(queue);
                      producer.setDeliveryMode(DeliveryMode.PERSISTENT);

                      TextMessage message = session.createTextMessage(createMessageText());
                      for(int count=0; count<messageCount; count++){
                        producer.send(message);
                      }
                      LOG.info("Done sending..");
                    } catch (JMSException e) {
                        if (e instanceof ResourceAllocationException || e.getCause() instanceof RequestTimedOutIOException) {
                          exceptionCount.incrementAndGet();
                        } else {
                            e.printStackTrace();
                        }
                      return;
                  }

              }
          };
          cx.start();
          Thread producerThread = new Thread(r);
          producerThread.start();
          producerThread.join(30000);
          cx.close();
          // We should have a few timeout exceptions as memory store will fill up
          assertTrue("No exception from the broker", exceptionCount.get() > 0);
      }
View Full Code Here

        ByteSequence content = getContent();
        if (content == null && text != null) {
            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.writeUTF8(dataOut, this.text);
View Full Code Here

            consumeMessge(i);
        }
    }

    protected Connection createConnection() throws Exception {
        ActiveMQConnection connection = (ActiveMQConnection) super.createConnection();
        connection.getPrefetchPolicy().setQueuePrefetch(prefetchSize);
        connection.getPrefetchPolicy().setTopicPrefetch(prefetchSize);
        return connection;
    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.ActiveMQConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.