Created
November 22, 2017 19:09
-
-
Save illerax/00234fbffd3e9c8a8ba64547bda04343 to your computer and use it in GitHub Desktop.
Grails Amazon SQS Example JMS configuration
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 grails.aws.sqs.example.config | |
import com.amazon.sqs.javamessaging.ProviderConfiguration | |
import com.amazon.sqs.javamessaging.SQSConnectionFactory | |
import com.amazonaws.auth.AWSCredentials | |
import com.amazonaws.auth.AWSStaticCredentialsProvider | |
import com.amazonaws.regions.Regions | |
import com.amazonaws.services.sqs.AmazonSQSClientBuilder | |
import grails.util.Holders | |
import org.springframework.context.annotation.Bean | |
import org.springframework.context.annotation.Configuration | |
import org.springframework.jms.annotation.EnableJms | |
import org.springframework.jms.config.DefaultJmsListenerContainerFactory | |
import org.springframework.jms.core.JmsTemplate | |
/** | |
* Created by Evgeny Smirnov <illerax@gmail.com> | |
*/ | |
@Configuration | |
@EnableJms | |
class JmsConfig { | |
/* | |
* SQSConnectionFactory class implements the ConnectionFactory interface as defined by the JMS standard, | |
* allowing it to be used with standard JMS interfaces and classes to connect to SQS | |
* */ | |
SQSConnectionFactory connectionFactory = | |
new SQSConnectionFactory( | |
new ProviderConfiguration(), | |
AmazonSQSClientBuilder.standard() | |
.withRegion(Regions.US_WEST_2) | |
.withCredentials(new AWSStaticCredentialsProvider( | |
[ | |
getAWSAccessKeyId: { Holders.config.amazon.key }, | |
getAWSSecretKey : { Holders.config.amazon.secret } | |
] as AWSCredentials)) | |
) | |
//Will be used to create listeners | |
@Bean | |
DefaultJmsListenerContainerFactory jmsListenerContainerFactory() { | |
new DefaultJmsListenerContainerFactory( | |
connectionFactory: this.connectionFactory | |
) | |
} | |
//Will be used to send messages | |
@Bean | |
JmsTemplate defaultJmsTemplate() { | |
new JmsTemplate(this.connectionFactory) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment