Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public MessageSenderGateway(String queueName) {
- if (queueName != null) {
- try {
- Properties props = new Properties();
- props.setProperty("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
- props.setProperty("java.naming.provider.url", "tcp://localhost:61616");
- props.put("queue." + queueName, queueName);
- Context jndiContext = new InitialContext(props);
- ConnectionFactory connectionFactory = (ConnectionFactory)jndiContext.lookup("ConnectionFactory");
- this.connection = connectionFactory.createConnection();
- this.session = this.connection.createSession(false, 1);
- this.producer = this.session.createProducer((Destination)null);
- this.destination = (Destination)jndiContext.lookup(queueName);
- this.connection.start();
- } catch (JMSException | NamingException e) {
- e.printStackTrace();
- }
- }
- }
- public MessageReceiverGateway(String queueName) {
- if (queueName != null) {
- try {
- Properties props = new Properties();
- props.setProperty("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
- props.setProperty("java.naming.provider.url", "tcp://localhost:61616");
- props.put("queue." + queueName, queueName);
- Context jndiContext = new InitialContext(props);
- ConnectionFactory connectionFactory = (ConnectionFactory)jndiContext.lookup("ConnectionFactory");
- this.connection = connectionFactory.createConnection();
- this.session = this.connection.createSession(false, 1);
- this.destination = (Destination)jndiContext.lookup(queueName);
- this.consumer = this.session.createConsumer(this.destination);
- this.connection.start();
- } catch (JMSException | NamingException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement