public static void main(String[] args) {

        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", BROKER_URL);
        Connection connection = null;

        try {
            Topic senderTopic = new ActiveMQTopic(System.getProperty("topicName"));

            connection = connectionFactory.createConnection("admin", "password");

            Session senderSession = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
            MessageProducer sender = senderSession.createProducer(senderTopic);

            Session receiverSession = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);

            String policyType = System.getProperty("wildcard", ".*");
            String receiverTopicName = senderTopic.getTopicName() + policyType;
            Topic receiverTopic = receiverSession.createTopic(receiverTopicName);

            MessageConsumer receiver = receiverSession.createConsumer(receiverTopic);
            receiver.setMessageListener(new MessageListener() {
                public void onMessage(Message message) {
                    try {
                        if (message instanceof TextMessage) {
                            String text = ((TextMessage) message).getText();
                            System.out.println("We received a new message: " + text);
                        }
                    } catch (JMSException e) {
                        System.out.println("Could not read the receiver's topic because of a JMSException");
                    }
                }
            });

            connection.start();
            System.out.println("Listening on '" + receiverTopicName + "'");
            System.out.println("Enter a message to send: ");

            Scanner inputReader = new Scanner(System.in);

            while (true) {
                String line = inputReader.nextLine();
                if (line == null) {
                    System.out.println("Done!");
                    break;
                } else if (line.length() > 0) {
                    try {
                        TextMessage message = senderSession.createTextMessage();
                        message.setText(line);
                        System.out.println("Sending a message: " + message.getText());
                        sender.send(message);
                    } catch (JMSException e) {
                        System.out.println("Exception during publishing a message: ");
                    }
                }
            }

            receiver.close();
            receiverSession.close();
            sender.close();
            senderSession.close();

        } catch (Exception e) {
            System.out.println("Caught exception!");
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (JMSException e) {
                    System.out.println("When trying to close connection: ");
                }
            }
        }

    }