短信网关模块搭建和多线程消费。

master
Administrator 2 years ago
parent e6d3e03ac1
commit f8937b3af6

@ -116,6 +116,7 @@ public class PushReportListener {
//3、得到响应后确认是否为SUCCESS //3、得到响应后确认是否为SUCCESS
return flag; return flag;
} }
/** /**
* *
* @param report * @param report

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>beacon-cloud</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>beacon-smsgateway</artifactId>
<name>短信网关模块的模板</name>
<dependencies>
<!-- start-web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- nacos-dis-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- nacos-config-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- 公共组件common-->
<dependency>
<groupId>com.mashibing</groupId>
<artifactId>beacon-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- RabbitMQ依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,19 @@
package com.mashibing.smsgateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author zjw
* @description
*/
@SpringBootApplication
@EnableDiscoveryClient
public class SmsGatewayStarterApp {
public static void main(String[] args) {
SpringApplication.run(SmsGatewayStarterApp.class,args);
}
}

@ -0,0 +1,29 @@
package com.mashibing.smsgateway.config;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* ~
* @author zjw
* @description
*/
//@Configuration
public class RabbitMQConfig {
// @Bean
public SimpleRabbitListenerContainerFactory gatewayContainerFactory(ConnectionFactory connectionFactory,
SimpleRabbitListenerContainerFactoryConfigurer configurer){
SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory = new SimpleRabbitListenerContainerFactory();
simpleRabbitListenerContainerFactory.setConcurrentConsumers(5);
simpleRabbitListenerContainerFactory.setPrefetchCount(10);
simpleRabbitListenerContainerFactory.setAcknowledgeMode(AcknowledgeMode.MANUAL);
configurer.configure(simpleRabbitListenerContainerFactory,connectionFactory);
return simpleRabbitListenerContainerFactory;
}
}

@ -0,0 +1,29 @@
package com.mashibing.smsgateway.mq;
import com.mashibing.common.model.StandardSubmit;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import java.io.IOException;
/**
* @author zjw
* @description
*/
@Component
@Slf4j
public class SmsGatewayListener {
@RabbitListener(queues = "${gateway.sendtopic}",containerFactory = "gatewayContainerFactory")
public void consume(StandardSubmit submit, Channel channel, Message message) throws IOException, InterruptedException {
log.info("【短信网关模块】 接收到消息 submit = {}",submit);
// =====================完成运营商交互,发送一次请求,接收两次响应==========================
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
}
}

@ -0,0 +1,16 @@
# 服务名称
spring:
application:
name: beacon-smsgateway
# 多环境
profiles:
active: dev
# nacos注册中心地址
cloud:
nacos:
discovery:
server-addr: 114.116.226.76:8848
# nacos配置中心地址:
config:
server-addr: 114.116.226.76:8848
file-extension: yml

@ -7,6 +7,8 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
/** /**
* @author zjw * @author zjw
@ -20,7 +22,6 @@ public class TestStarterApp {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(TestStarterApp.class,args); SpringApplication.run(TestStarterApp.class,args);
} }

@ -11,6 +11,7 @@
<module>beacon-strategy</module> <module>beacon-strategy</module>
<module>beacon-search</module> <module>beacon-search</module>
<module>beacon-push</module> <module>beacon-push</module>
<module>beacon-smsgateway</module>
</modules> </modules>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

Loading…
Cancel
Save