Browse Source

增加配置描述

luoguangyi 3 years ago
parent
commit
9bbde956c0

+ 9 - 1
README.md

@@ -1,3 +1,11 @@
 # iot-transfer
 
-kafka转发iot数据,适用于iot-project和iot-collect无法直接TCP连接的情况,通过iot-transfer进行转发通信,目前招商适用
+- ###### kafka转发iot数据,适用于iot-project和iot-collect无法直接TCP连接的情况,通过iot-transfer进行转发通信,目前招商适用;
+
+- ###### 程序一式两份,一份部署在云端,一份部署在边缘端,一式两份之间通过kafka通讯,实现内外网之间的iot数据通讯,
+
+- ###### iot-transfer通过模拟iot-collect/iot-control给iot-project提供服务,同时需要配置iot-collect/iot-control的地址实现转发数据到云端,
+
+- ###### 一式两份之间配置相同,通过配置文件中的iot.type.cloud和iot.type.edge来设置是部署在哪一侧;
+
+###### 

+ 17 - 0
iot-transfer.yml

@@ -0,0 +1,17 @@
+version: '3'
+services:
+  iot-control:
+    image: registry.persagy.com/ftp/iot-transfer:${tag}
+    container_name: iot-transfer
+    restart: always
+    ports:
+      # 服务暴露端口号,按环境调整
+      #8863 为服务端口,
+      - 8863:8863
+      #8851为模拟iot-collect数据通讯的端口,同application.yml中配置的iot.server.collect.tcp_bind_port
+      - 8851:8851
+      #8855为模拟iot-control数据通讯的端口,同application.yml中配置的iot.server.control.tcp_bind_port
+      - 8855:8855
+    volumes:
+      # 文件同级放config文件夹,文件夹下有 要包含application.yml等配置文件
+      - ./config/:/usr/persagy/iot-transfer/config/

+ 0 - 119
src/main/java/com/persagy/iottransfer/config/KafkaCommonConfig.java

@@ -1,119 +0,0 @@
-package com.persagy.iottransfer.config;
-
-import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
-import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
-import org.springframework.kafka.core.DefaultKafkaProducerFactory;
-import org.springframework.kafka.core.KafkaTemplate;
-import org.springframework.kafka.listener.ContainerProperties;
-
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * kafka配置,实际上,在KafkaAutoConfiguration中已经有默认的根据配置文件信息创建配置,但是自动配置属性没有涵盖所有
- * 我们可以自定义创建相关bean,进行如下配置
- *
- * @author zhoujy
- * @date 2018年12月17日
- **/
-@Configuration
-@EnableConfigurationProperties({KafkaProperties.class})
-@ConditionalOnProperty(prefix = "spring.kafka", name = "enable", havingValue = "true")
-public class KafkaCommonConfig implements InitializingBean {
-
-    private final KafkaProperties properties;
-    @Value("${spring.kafka.consumer.topics}")
-    private String topics;
-
-    public KafkaCommonConfig(KafkaProperties properties) {
-        this.properties = properties;
-    }
-
-    //构造消费者属性map,ConsumerConfig中的可配置属性比spring boot自动配置要多
-    private Map<String, Object> consumerProperties() {
-//        props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
-        return properties.buildConsumerProperties();
-    }
-
-    /**
-     * 不使用spring boot默认方式创建的DefaultKafkaConsumerFactory,重新定义创建方式
-     *
-     * @return
-     */
-    @Bean("consumerFactory")
-    public DefaultKafkaConsumerFactory consumerFactory() {
-        return new DefaultKafkaConsumerFactory(consumerProperties());
-    }
-
-
-    @Bean("listenerContainerFactory")
-    //个性化定义消费者
-    public ConcurrentKafkaListenerContainerFactory listenerContainerFactory(DefaultKafkaConsumerFactory consumerFactory) {
-        //指定使用DefaultKafkaConsumerFactory
-        ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory();
-        factory.setConsumerFactory(consumerFactory);
-
-        //设置消费者ack模式为手动,看需求设置
-        factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
-        //设置可批量拉取消息消费,拉取数量一次3,看需求设置
-        factory.setConcurrency(1);
-        factory.setBatchListener(true);
-        return factory;
-    }
-
-   /* @Bean
-     //代码创建方式topic
-    public NewTopic batchTopic() {
-        return new NewTopic("topic.quick.batch", 8, (short) 1);
-    }*/
-
-    //创建生产者配置map,ProducerConfig中的可配置属性比spring boot自动配置要多
-    private Map<String, Object> producerProperties() {
-        return properties.buildProducerProperties();
-    }
-
-    /**
-     * 不使用spring boot的KafkaAutoConfiguration默认方式创建的DefaultKafkaProducerFactory,重新定义
-     *
-     * @return
-     */
-    @Bean("produceFactory")
-    public DefaultKafkaProducerFactory produceFactory() {
-        return new DefaultKafkaProducerFactory(producerProperties());
-    }
-
-
-    /**
-     * 不使用spring boot的KafkaAutoConfiguration默认方式创建的KafkaTemplate,重新定义
-     *
-     * @param produceFactory
-     * @return
-     */
-    @Bean
-    public KafkaTemplate kafkaTemplate(DefaultKafkaProducerFactory produceFactory) {
-        return new KafkaTemplate(produceFactory);
-    }
-
-    @Override
-    public void afterPropertiesSet() throws Exception {
-        String topicName = wireTopics();
-        System.setProperty("topicName", topicName);
-        System.out.println("### set system config topic:{}" + topicName);
-    }
-
-    private String wireTopics() {
-        Set<String> topicSet = new HashSet<>();
-        topicSet.add(topics);
-        return StringUtils.join(topicSet, ",");
-    }
-
-}

+ 39 - 12
src/main/resources/application.yml

@@ -1,13 +1,22 @@
 server:
-  #需要更改
-  port: 8881
+  #端口,需要更改
+  port: 8863
 spring:
   # 应用名称
   application:
     name: iot-transfer
   kafka:
     enable: true
-    bootstrap-servers: 192.168.64.16:9092
+    #kafka-servers,需要更改
+    bootstrap-servers: 192.168.64.16:9092 #120.24.88.152:9093,120.24.91.199:9093,120.24.81.140:9093 #192.168.64.16:9092
+    #ssl认证,根据情况配置,store-location相关的认证文件对应添加,需要更改
+    ssl:
+      key-password: test
+      key-store-location: /usr/persagy/iot-transfer/server.keystore.jks
+      key-store-password: test
+      key-store-type: JKS
+      trust-store-location: /usr/persagy/iot-transfer/client.truststore.jks
+      trust-store-password: test
     producer:
       # 发生错误后,消息重发的次数。
       retries: 2
@@ -23,8 +32,11 @@ spring:
       # acks=1 : 只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。
       # acks=all :只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。
       acks: 1
-      properties:
-        max.request.size: 50000000
+#      properties:
+#        max.request.size: 50000000
+      #   生产着启用SSL,需要启用的环境放开,不需要启用的环境注释掉下面一行 ,需要更改
+      security:
+        protocol: SSL
     consumer:
       topics:
       # 自动提交的时间间隔 在spring boot 2.X 版本中这里采用的是值的类型为Duration 需要符合特定的格式,如1S,1M,2H,5D
@@ -41,8 +53,11 @@ spring:
       key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
       # 值的反序列化方式
       value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
-      properties:
-        max.partition.fetch.bytes: 50000000
+#      properties:
+#        max.partition.fetch.bytes: 50000000
+      #   消费者启用SSL,需要启用的环境放开,不需要启用的环境注释掉下面一行 ,需要更改
+      security:
+        protocol: SSL
     listener:
       # 在侦听器容器中运行的线程数。
       concurrency: 5
@@ -50,15 +65,20 @@ spring:
       ack-mode: manual_immediate
       missing-topics-fatal: false
 iot:
+  # 程序一式两份,一份部署在云端,一份部署在边缘端,一式两份之间通过kafka通讯,实现内外网之间的iot数据通讯
   type:
-    cloud: true
+    # 程序部署位置类型,部署在云端一侧的,需要设置cloud为true,edge为false,需要更改
+    cloud: false
+    # 程序部署位置类型,部署在边缘端一侧的,需要设置cloud为false,edge为true,需要更改
     edge: false
   server:
+    #同原来iot-collect中的util.xml配置,用于部署在需要更改edge边缘端给iot-project通讯使用,需要更改
     collect:
       tcp_enable: true
       tcp_bind_ip: 0.0.0.0
+      #需要更改
       tcp_bind_port: 8851
-      udp_enable: true
+      udp_enable: false
       udp_bind_ip: 0.0.0.0
       udp_bind_port: 8851
       max_size: 1000
@@ -69,8 +89,9 @@ iot:
     control:
       tcp_enable: true
       tcp_bind_ip: 0.0.0.0
+      #需要更改
       tcp_bind_port: 8855
-      udp_enable: true
+      udp_enable: false
       udp_bind_ip: 0.0.0.0
       udp_bind_port: 8855
       max_size: 1000
@@ -79,9 +100,12 @@ iot:
       separate_end: )
       compress: false
   clients:
+    #同原来iot-project中的util.xml配置,配置iot转发程序要连接的的iot-collect/iot-control地址,需要更改
     - protocol: TCP
+      #iot-collect IP,需要更改
       target_ip: 127.0.0.1
-      target_port: 8861
+      #iot-collect port,需要更改
+      target_port: 8851
       max_size: 1000
       sleepcount: 1000
       separate_begin: (
@@ -92,8 +116,10 @@ iot:
       server_is_iot_collect: true
       server_is_iot_control: false
     - protocol: TCP
+      #iot-control IP,需要更改
       target_ip: 127.0.0.1
-      target_port: 8862
+      #iot-control port,需要更改
+      target_port: 8855
       max_size: 1000
       sleepcount: 1000
       separate_begin: (
@@ -104,6 +130,7 @@ iot:
       server_is_iot_collect: false
       server_is_iot_control: true
   projects:
+    #配置要转发的项目,只有列表中配置的项目的数据才会转发,否则丢弃,默认配置了招商的四个项目,需要更改
     - id: 4403050019
       PjId: Pj4403050019
       name: 深圳太子广场汇港二期