Created
May 4, 2016 22:14
-
-
Save maxschremser/0012b0d6bec27cc395e143307fe33bd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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