Package org.apache.activemq

Examples of org.apache.activemq.ActiveMQSession


        broker.addConnector(url);
        broker.start();

        ActiveMQConnectionFactory connFac = new ActiveMQConnectionFactory(url);
        Connection conn = connFac.createConnection();
        ActiveMQSession session = (ActiveMQSession)conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
        queue = session.createQueue("CheckAccounts");
        MessageProducer producer = session.createProducer(queue);
        MapMessage map = session.createMapMessage();

        for (int i = 0; i < 3; i++) {
            String accountNumber = "C00" + (i + 1);
            float balance = (float)(1000.0 + Math.random() * 200.0);
            map.setStringProperty("accountNumber", accountNumber);
            map.setFloatProperty("balance", balance);

            map.setString("accountNumber", accountNumber);
            map.setFloat("balance", balance);

            producer.send(map);
        }
        session.commit();
        conn.close();
    }
View Full Code Here


    protected void save(String accountNumber, float balance) throws AccountNotFoundException {
        try {
            ActiveMQConnectionFactory connFac = new ActiveMQConnectionFactory(url);
            Connection conn = connFac.createConnection();
            conn.start();
            ActiveMQSession session = (ActiveMQSession)conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
            MessageConsumer consumer = session.createConsumer(queue, "accountNumber = '" + accountNumber + "'");
            Message msg = consumer.receive(1000);
            if (msg == null) {
                conn.close();
                throw new AccountNotFoundException(accountNumber);
            }
            MapMessage map = session.createMapMessage();
            map.setStringProperty("accountNumber", accountNumber);
            map.setFloatProperty("balance", balance);

            map.setString("accountNumber", accountNumber);
            map.setFloat("balance", balance);

            MessageProducer producer = session.createProducer(queue);
            producer.send(map);
            conn.close();

        } catch (JMSException e) {
            throw new ServiceRuntimeException(e);
View Full Code Here

        String content = "hello world " + System.currentTimeMillis();
        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        writer.append(content);
        writer.close();

        ActiveMQSession session = (ActiveMQSession) connection.createSession(
                false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(destination);
        MessageConsumer consumer = session.createConsumer(destination);
        BlobMessage message = session.createBlobMessage(file);

        producer.send(message);
        Thread.sleep(1000);

        // check message send
View Full Code Here

   
    protected void useConnectionWithBlobMessage(Connection connection) throws Exception {
        connection.setClientID(clientID);
        connection.start();
        ActiveMQSession session = (ActiveMQSession) connection.createSession(transacted, authMode);
        destination = createDestination();
        MessageProducer producer = session.createProducer(destination);
        for (int i = 0; i < MESSAGE_COUNT; i++) {
            BlobMessage message = session.createBlobMessage(new URL("http://foo.bar/test"));
            message.setIntProperty("counter", i);
            message.setJMSCorrelationID("MyCorrelationID");
            message.setJMSReplyTo(new ActiveMQQueue("MyReplyTo"));
            message.setJMSType("MyType");
            message.setJMSPriority(5);
View Full Code Here

       
        final int messageCount = Queue.MAX_PAGE_SIZE + 10;
        final CountDownLatch latch = new CountDownLatch(1);
       
        serverSession = serverConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        ActiveMQSession s = (ActiveMQSession) serverSession;
        s.setSessionAsyncDispatch(true);
       
        MessageConsumer serverConsumer = serverSession.createConsumer(serverDestination);
        serverConsumer.setMessageListener(new MessageListener() {
          
            public void onMessage(Message msg) {
View Full Code Here

     * @param transacted
     * @return
     * @throws JMSException
     */
    private ManagedSessionProxy createSessionProxy(boolean transacted, int acknowledgeMode) throws JMSException {
        ActiveMQSession session = (ActiveMQSession)getConnection().createSession(transacted, acknowledgeMode);
        ManagedTransactionContext txContext = new ManagedTransactionContext(managedConnection.getTransactionContext());
        session.setTransactionContext(txContext);
        ManagedSessionProxy p = new ManagedSessionProxy(session);
        p.setUseSharedTxContext(managedConnection.isInManagedTx());
        sessions.add(p);
        return p;
    }
View Full Code Here

    }

    protected void useConnectionWithBlobMessage(Connection connection) throws Exception {
        connection.setClientID(clientID);
        connection.start();
        ActiveMQSession session = (ActiveMQSession) connection.createSession(transacted, authMode);
        destination = createDestination();
        MessageProducer producer = session.createProducer(destination);
        for (int i = 0; i < MESSAGE_COUNT; i++) {
            BlobMessage message = session.createBlobMessage(new URL("http://foo.bar/test"));
            message.setIntProperty("counter", i);
            message.setJMSCorrelationID("MyCorrelationID");
            message.setJMSReplyTo(new ActiveMQQueue("MyReplyTo"));
            message.setJMSType("MyType");
            message.setJMSPriority(5);
View Full Code Here

    }

    protected void useConnectionWithByteMessage(Connection connection) throws Exception {
        connection.setClientID(clientID);
        connection.start();
        ActiveMQSession session = (ActiveMQSession) connection.createSession(transacted, authMode);
        destination = createDestination();
        MessageProducer producer = session.createProducer(destination);
        for (int i = 0; i < MESSAGE_COUNT; i++) {
            BytesMessage message = session.createBytesMessage();
            message.writeBytes(("Message: " + i).getBytes());
            message.setIntProperty("counter", i);
            message.setJMSCorrelationID("MyCorrelationID");
            message.setJMSReplyTo(new ActiveMQQueue("MyReplyTo"));
            message.setJMSType("MyType");
View Full Code Here

        waitForBridgeFormation(b, 1, 0);

        ActiveMQConnectionFactory sendFactory = createConnectionFactory(a);
        ActiveMQConnection sendConnection = createConnection(sendFactory);

        ActiveMQSession sendSession = (ActiveMQSession)sendConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = sendSession.createProducer(sendQ);
        ActiveMQTempQueue realReplyQ = (ActiveMQTempQueue) sendSession.createTemporaryQueue();
        TextMessage message = sendSession.createTextMessage("1");
        message.setJMSReplyTo(realReplyQ);
        producer.send(message);
        LOG.info("request sent");

        // responder
        ActiveMQConnectionFactory consumerFactory = createConnectionFactory(b);
        ActiveMQConnection consumerConnection = createConnection(consumerFactory);

        ActiveMQSession consumerSession = (ActiveMQSession)consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = consumerSession.createConsumer(sendQ);
        TextMessage received = (TextMessage) consumer.receive(receiveTimeout);
        assertNotNull("got request from sender ok", received);

        LOG.info("got request, sending reply");

        MessageProducer consumerProducer = consumerSession.createProducer(received.getJMSReplyTo());
        consumerProducer.send(consumerSession.createTextMessage("got " + received.getText()));
        // temp dest on reply broker tied to this connection, setOptimizedDispatch=true ensures
        // message gets delivered before destination is removed
        consumerConnection.close();

        // reply consumer
View Full Code Here

        final int messageCount = Queue.MAX_PAGE_SIZE + 10;
        final CountDownLatch latch = new CountDownLatch(1);

        serverSession = serverConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        ActiveMQSession s = (ActiveMQSession) serverSession;
        s.setSessionAsyncDispatch(true);

        MessageConsumer serverConsumer = serverSession.createConsumer(serverDestination);
        serverConsumer.setMessageListener(new MessageListener() {

            public void onMessage(Message msg) {
View Full Code Here

TOP

Related Classes of org.apache.activemq.ActiveMQSession

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.