給aws sqs發(fā)隊列消息

1.引入包:

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws-messaging</artifactId>
        </dependency>

2.在配置文件yml中定義隊列的名字,并且定義一個參數(shù)類,在這個類中定義priceChangedSqs為aws里的隊列名字。

3.配置一個QueueMessagingTemplate類引用這個sqs隊列

@Configuration
public class ApplicationConfiguration {

    private final PricingProperties pricingProperties;

    @Autowired
    public ApplicationConfiguration(
                    final PricingProperties pricingProperties ) {
        this.pricingProperties = pricingProperties;
    }

    @Bean
    public QueueMessagingTemplate queueMessagingTemplate( final AmazonSQSAsync amazonSQSAsync,
                                                          final ResourceIdResolver resourceIdResolver ) {
        final QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSQSAsync, resourceIdResolver );
        queueMessagingTemplate.setDefaultDestinationName( pricingProperties.getPriceChangedSqs() ); // 通過第二步,獲取yml里的隊列名

        return queueMessagingTemplate;
    }

}

4.使用 queueMessagingTemplate 發(fā)送消息

public class PriceSendToSqs {
    private final QueueMessagingTemplate queueMessagingTemplate;
    public void sendToSqs(  SupplierArticlePrice price ) {
      ExchangeableArticlePrice exchangeableArticlePrice = new ExchangeableArticlePrice( price );
            queueMessagingTemplate.convertAndSend( exchangeableArticlePrice );
        }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 想找一個生活用品,卻不知道放在哪里,亂找一通,最后自我安慰,找東西的時候他們總玩捉迷藏,不找了就出來了。 這次又碰...
    點滴中成長閱讀 2,238評論 11 94
  • 我們常聽到的話,不是文章標題里面寫的,而一般是【別急,您慢慢說】。您慢慢說,用來安慰一些情緒激烈又笨口拙舌的人或許...
    AaronWu閱讀 430評論 0 0
  • 夢想一定要有的,萬一哪一天有機會實現(xiàn)呢?小朋友,有沒有自己的夢想呢?如果你的夢想受到別人的嘲笑或者歧視...
    666卓越閱讀 334評論 0 1
  • 那年我考研。考了兩年沒考上。我坐在家里椅子上思考了三個月。一邊學車一邊看書一邊思考。沒想明白。心里絕望極了。努力咋...
    月下奔跑的驢閱讀 230評論 0 0

友情鏈接更多精彩內(nèi)容