Skip to content

Instantly share code, notes, and snippets.

@maxschremser
Created May 4, 2016 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxschremser/0012b0d6bec27cc395e143307fe33bd4 to your computer and use it in GitHub Desktop.
Save maxschremser/0012b0d6bec27cc395e143307fe33bd4 to your computer and use it in GitHub Desktop.
package com.schremser.spring.jms.server;
import com.schremser.spring.jms.core.JndiConfiguration;
import com.schremser.spring.jms.server.receiver.QueueMessageReceiver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import javax.jms.Destination;
import java.io.IOException;
@SpringBootApplication
@Import(JndiConfiguration.class)
@PropertySource("classpath:default.properties")
public class JmsServer {
private final static Logger log = LoggerFactory.getLogger(JmsServer.class);
@Autowired JndiConfiguration jndi;
@Bean
public QueueMessageReceiver queueMessageReceiver() {
return new QueueMessageReceiver();
}
@Bean
DefaultMessageListenerContainer queueMessageListener() {
DefaultMessageListenerContainer defaultMessageListenerContainer = new DefaultMessageListenerContainer();
defaultMessageListenerContainer.setConnectionFactory(jndi.connectionFactoryProxy());
defaultMessageListenerContainer.setDestination((Destination) jndi.importQueue().getObject());
defaultMessageListenerContainer.setSessionTransacted(true);
defaultMessageListenerContainer.setConcurrentConsumers(1);
defaultMessageListenerContainer.setMaxConcurrentConsumers(7);
defaultMessageListenerContainer.setMessageListener(queueMessageReceiver());
defaultMessageListenerContainer.afterPropertiesSet();
defaultMessageListenerContainer.start();
return defaultMessageListenerContainer;
}
@Override
public String toString() {
return jndi.toString();
}
public static void main(String[] args) throws IOException {
ConfigurableApplicationContext context = SpringApplication.run(JmsServer.class);
log.info("Waiting for requests ...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment