long
2023-09-02 e379948bb83ebcc9ce0c467a7b970f74bc00e9a1
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.tool;
2
3 import java.io.IOException;
4 import java.util.Properties;
5
6 public class ResourceUtil {
7
8
9     //是否开启上层MES接口
10     public static String MES_TERMINATED;
11     //是否开启PLC采集
12     public static String PLC_TERMINATED;
13
14
15     //消费者变量
16     public static String CONSUMER_ZOOKEEPER_CONNECT;
17     public static String CONSUMER_SERVERS;
18     public static String CONSUMER_ENABLE_AUTO_COMMIT;
19     public static String CONSUMER_SESSION_TIMEOUT;
20     public static String CONSUMER_AUTO_COMMIT_INTERVAL;
21     public static String CONSUMER_AUTO_OFFSET_RESET;
22     public static String CONSUMER_GROUP_ID;
23     public static String CONSUMER_CONCURRENCY;
24
25     //生产者变量
26     public static String PRODUCER_SERVERS;
27     public static String PRODUCER_RETRIES;
28     public static String PRODUCER_BATCH_SIZE;
29     public static String PRODUCER_LINGER;
30     public static String PRODUCER_BUFFER_MEMORY;
31
32     //定义接收频率
33     public static int  RECEIVE_WORK_ORDER_TIME;
34     public static int  RECEIVE_PRODUCTION_LINE_CMD_TIME;
35
36     //定义发送频率
37     public static int  SEND_PRODUCTION_REPORT_TIME;
38     public static int  SEND_PRODUCTION_RESULT_TIME;
39     public static int  SEND_PRODUCTION_LINE_STATUS_TIME;
40     public static int  SEND_PRODUCTION_LINE_CMD_RES_TIME;
41     public static int  SEND_EQUIPMENT_STATUS_TIME;
42     public static int  SEND_EQUIPMENT_ALARM_TIME;
43     public static int  SEND_TAKT_TIME_TIME;
44
45
46     public void readFile(){
47         try{
48             Properties prop = new Properties();
49             prop.load(this.getClass().getResourceAsStream("/kafka.properties"));
50
51             //是否开启上层MES接口
52             MES_TERMINATED = prop.getProperty("kafka.mes.terminated");
53             //是否开启PLC采集
54             PLC_TERMINATED = prop.getProperty("plc.terminated");
55
56             //消费者变量
57             CONSUMER_ZOOKEEPER_CONNECT = prop.getProperty("kafka.consumer.zookeeper.connect");
58             CONSUMER_SERVERS = prop.getProperty("kafka.consumer.servers");
59             CONSUMER_ENABLE_AUTO_COMMIT = prop.getProperty("kafka.consumer.enable.auto.commit");
60             CONSUMER_SESSION_TIMEOUT = prop.getProperty("kafka.consumer.session.timeout");
61             CONSUMER_AUTO_COMMIT_INTERVAL = prop.getProperty("kafka.consumer.auto.commit.interval");
62             CONSUMER_AUTO_OFFSET_RESET = prop.getProperty("kafka.consumer.auto.offset.reset");
63             CONSUMER_GROUP_ID = prop.getProperty("kafka.consumer.group.id");
64             CONSUMER_CONCURRENCY = prop.getProperty("kafka.consumer.concurrency");
65
66             //生产者变量
67             PRODUCER_SERVERS = prop.getProperty("kafka.producer.servers");
68             PRODUCER_RETRIES = prop.getProperty("kafka.producer.retries");
69             PRODUCER_BATCH_SIZE = prop.getProperty("kafka.producer.batch.size");
70             PRODUCER_LINGER = prop.getProperty("kafka.producer.linger");
71             PRODUCER_BUFFER_MEMORY = prop.getProperty("kafka.producer.buffer.memory");
72
73             //接收时间
74             RECEIVE_WORK_ORDER_TIME = Integer.parseInt(prop.getProperty("receive.work.order.time"));
75             RECEIVE_PRODUCTION_LINE_CMD_TIME = Integer.parseInt(prop.getProperty("receive.production.line.cmd.time"));
76
77             //发送时间
78             SEND_PRODUCTION_REPORT_TIME = Integer.parseInt(prop.getProperty("send.production.report.time"));
79             SEND_PRODUCTION_RESULT_TIME = Integer.parseInt(prop.getProperty("send.production.result.time"));
80             SEND_PRODUCTION_LINE_STATUS_TIME = Integer.parseInt(prop.getProperty("send.production.line.status.time"));
81             SEND_PRODUCTION_LINE_CMD_RES_TIME = Integer.parseInt(prop.getProperty("send.production.line.cmd.res.time"));
82             SEND_EQUIPMENT_STATUS_TIME = Integer.parseInt(prop.getProperty("send.equipment.status.time"));
83             SEND_EQUIPMENT_ALARM_TIME = Integer.parseInt(prop.getProperty("send.equipment.alarm.time"));
84             SEND_TAKT_TIME_TIME = Integer.parseInt(prop.getProperty("send.takt.time.time"));
85
86             System.out.println("成功读取配置文件!");
87         }catch (IOException e){
88             e.printStackTrace();
89         }
90
91     }
92 }