Hey Gordon, here is what I really mean. I think that this is way more useful
:


import java.util.Properties;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class AlternateExchangeTest {
        
        public static void main(String[] args) throws JMSException, 
NamingException
{
                new AlternateExchangeTest().runTest();
        }
        
        
        private void runTest() throws JMSException, NamingException { 
                
                Connection connection = null;
                Context context = null;
                
        try { 
                Properties properties = new Properties(); 
           
properties.load(this.getClass().getResourceAsStream("/mrg/mrg.properties")); 
            properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.qpid.jndi.PropertiesFileInitialContextFactory");
            
            context = new InitialContext(properties);   
            
            ConnectionFactory connectionFactory = (ConnectionFactory)
context.lookup("qpidConnectionfactory"); 
            connection = connectionFactory.createConnection();   
            connection.start(); 

            Session
session=connection.createSession(false,Session.CLIENT_ACKNOWLEDGE); 
            Queue myQueue = session.createQueue("MY_QUEUE; {create:always,
delete:receiver, assert:always, node:{x-declare:{auto-delete:true,
exclusive: true, alternate-exchange: FANOUT_EXCHANGE}}}");  
            
            TextMessage message = session.createTextMessage("Sample");
            MessageProducer producer = session.createProducer(myQueue);
            producer.send(message);
            
            /**
             * You could un-comment this sleep to see that the queue
MY_QUEUE really exists and it has one message
             */
            //Thread.sleep(1000000);
            
            MessageConsumer messageConsumer =
session.createConsumer(myQueue);
            
            Message messageResponse = null;
            
            System.out.println("Receiving!");
            
            do{
                messageResponse = messageConsumer.receive(100);
            } while(messageResponse == null);
            
            System.out.println("Received!");
            
            /**
             * When I end up here, the queue exists and it has one message
according to qpid-stat -q
             * Then I stop the Thread - big red button in Eclipse Console
             * run qpid-stat -q again and notice that the queue is now
deleted, but the FANOUT_EXCHANGE reports no messages
             * thus my message is deleted and forever gone?
             */
            Thread.sleep(1000000);
            
            
        } catch (Exception exp) { 
                exp.printStackTrace(); 
        } finally{
                connection.close();
                context.close();
        }
    } 
}

Thank You,
Eugene.

--
View this message in context: 
http://apache-qpid-developers.2158895.n2.nabble.com/Red-Hat-MRG-alt-exchange-tp7368166p7371609.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org
For additional commands, e-mail: dev-h...@qpid.apache.org

Reply via email to