简体   繁体   中英

spring cloud aws annotation driven queue listener

I'm trying to write a web application that consumes AWS SQS using spring cloud AWS annotation-driven queue listener, here is how my code looks like:

XML AWS Beans:

 <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aws-context="http://www.springframework.org/schema/cloud/aws/context" xmlns:aws-messaging="http://www.springframework.org/schema/cloud/aws/messaging" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/cloud/aws/context http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context.xsd http://www.springframework.org/schema/cloud/aws/messaging http://www.springframework.org/schema/cloud/aws/messaging/spring-cloud-aws-messaging"> <!-- Define global credentials for all the AWS clients --> <aws-context:context-credentials> <aws-context:instance-profile-credentials/> <aws-context:simple-credentials access-key="${accessKey:}" secret-key="${secretKey:}"/> </aws-context:context-credentials> <!-- Define global region --> <aws-context:context-region region="EU_WEST_1"/> <!-- Cloud Formation Stack --> <aws-context:stack-configuration stack-name="StackName"/> <aws-messaging:annotation-driven-queue-listener /> </beans> 

then i wrote this class that have a method with SqsListener anotation, which prints hello to the console :

 package com.example.demo; import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener; public class AWSSQSListner { @SqsListener("queue-name") public void queueListener(Person person) { System.out.print("\\"Hello\\""); } } 

this is my gradle build file:

 Gradle build file: buildscript { ext { springBootVersion = '2.0.5.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } ext { springCloudVersion = 'Finchley.SR1' } dependencies { compile('org.springframework.boot:spring-boot-starter-web-services') compile('org.springframework.cloud:spring-cloud-starter-aws') compile('org.springframework.cloud:spring-cloud-starter-aws-messaging') testCompile('org.springframework.boot:spring-boot-starter-test') } dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } 

but when i run the app nothings hapend, Im new to java and spring boot, is there any thing im doing wrong

我只需要向AWSSQSListner类添加@Component批注,它就可以工作,也不需要XML AWS Bean

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM