This page refers to an old MINA based transport layer used by the Qpid Java components until 0.12.

Sample Code

Here is a template for correctly creating a unit test that will use the InVM Broker.

    @Before
    public void initialSetup() throws Exception
    {
        createVMBroker();

        //Any other setup code 

    }

    public void createVMBroker()
    {
        try
        {
            TransportConnection.createVMBroker(1);
            // Multiple Brokers can be created by passing in a different port. The above is connected to with the url vm://:1
        }
        catch (AMQVMBrokerCreationException e)
        {
            Assert.fail("Unable to create broker: " + e);
        }
    }

    @After
    public void stopVmBroker()
    {
        // If you created a connection in the @Before be sure to close it before you kill the broker or 
        //  it will attempt failover, and recreate the broker.
        TransportConnection.killVMBroker(1);
        //Remember to kill any other brokers you create
    }

    @Test
    public void yourTest code() throws Exception
    {
        //If you do your connection setup here
        Connection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "test");


        // Be sure to close it before you end the test
        con.close();
    }
  • No labels