spring 云 aws 注释驱动的队列侦听器
spring cloud aws annotation driven queue listener
我正在尝试使用 spring 云 AWS 注释驱动的队列侦听器编写一个使用 AWS SQS 的 Web 应用程序,我的代码如下所示:
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>
然后我写了这个 class,它有一个带有 SqsListener 注释的方法,它向控制台打印 hello :
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\"");
}
}
这是我的 gradle 构建文件:
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}"
}
}
但是当我 运行 应用程序没有发生任何事情时,我是 java 和 spring 引导的新手,我有什么地方做错了吗
我只需要将 @Component 注释添加到 AWSSQSListner class 就可以了,也不需要 XML AWS bean
我正在尝试使用 spring 云 AWS 注释驱动的队列侦听器编写一个使用 AWS SQS 的 Web 应用程序,我的代码如下所示:
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>
然后我写了这个 class,它有一个带有 SqsListener 注释的方法,它向控制台打印 hello :
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\"");
}
}
这是我的 gradle 构建文件:
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}"
}
}
但是当我 运行 应用程序没有发生任何事情时,我是 java 和 spring 引导的新手,我有什么地方做错了吗
我只需要将 @Component 注释添加到 AWSSQSListner class 就可以了,也不需要 XML AWS bean