作者 王勇

sdk,初步完善,备份

1 -URL_CONSUMER_ONE=http://192.168.1.33:9032/bus/rabbit/consumer_one  
2 -URL_CONSUMER_MORE=http://192.168.1.33:9032/bus/rabbit/consumer_more  
@@ -27,6 +27,7 @@ @@ -27,6 +27,7 @@
27 </properties> 27 </properties>
28 28
29 <dependencies> 29 <dependencies>
  30 +
30 <dependency> 31 <dependency>
31 <groupId>org.springframework.boot</groupId> 32 <groupId>org.springframework.boot</groupId>
32 <artifactId>spring-boot-starter</artifactId> 33 <artifactId>spring-boot-starter</artifactId>
@@ -38,12 +39,6 @@ @@ -38,12 +39,6 @@
38 </dependency> 39 </dependency>
39 40
40 <dependency> 41 <dependency>
41 - <groupId>org.springframework.boot</groupId>  
42 - <artifactId>spring-boot-starter-log4j</artifactId>  
43 - <version>1.3.8.RELEASE</version>  
44 - </dependency>  
45 -  
46 - <dependency>  
47 <groupId>com.squareup.okhttp3</groupId> 42 <groupId>com.squareup.okhttp3</groupId>
48 <artifactId>okhttp</artifactId> 43 <artifactId>okhttp</artifactId>
49 <version>4.8.1</version> 44 <version>4.8.1</version>
@@ -70,6 +65,7 @@ @@ -70,6 +65,7 @@
70 <dependency> 65 <dependency>
71 <groupId>org.projectlombok</groupId> 66 <groupId>org.projectlombok</groupId>
72 <artifactId>lombok</artifactId> 67 <artifactId>lombok</artifactId>
  68 + <optional>true</optional>
73 </dependency> 69 </dependency>
74 70
75 </dependencies> 71 </dependencies>
@@ -14,7 +14,7 @@ public class MyTestMethods { @@ -14,7 +14,7 @@ public class MyTestMethods {
14 private static final String url_product_new = "http://192.168.1.53:12343/message-bus-send/bus/rabbit/product_new"; 14 private static final String url_product_new = "http://192.168.1.53:12343/message-bus-send/bus/rabbit/product_new";
15 private static final String url_product_old = "http://192.168.1.53:12343/message-bus-send/bus/rabbit/product_old"; 15 private static final String url_product_old = "http://192.168.1.53:12343/message-bus-send/bus/rabbit/product_old";
16 private static final String url_consumer_one = "http://192.168.1.53:12343/message-bus-receive/bus/rabbit/consumer_one"; 16 private static final String url_consumer_one = "http://192.168.1.53:12343/message-bus-receive/bus/rabbit/consumer_one";
17 - private static final String url_consumer_more = "http://192.168.1.53:12343/message-bus-receive/bus/rabbit/consumer_more2"; 17 + private static final String url_consumer_more = "http://192.168.1.53:12343/message-bus-receive/bus/rabbit/consumer_more";
18 18
19 private static final String token = 19 private static final String token =
20 "Bearer eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ6aWNoZW5nIiwiZXhwIjoxNTk5NDk3MzU1fQ.YI69vs8pV99v7hnt6xGX5c4wvMPBj6tgsjiI4JJbW2Irj-sUW1stskQ25-G5cDRI-qoZFQTlvRvGVFR97arFD9gwAIB8Gfz4Sog-QC1wLDS3xStvygsCDabQmaF8JaE_zWbtJ7Izs7Jd45VOiI4CS_uZY5dsgODB5IqW1hwj-JY"; 20 "Bearer eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ6aWNoZW5nIiwiZXhwIjoxNTk5NDk3MzU1fQ.YI69vs8pV99v7hnt6xGX5c4wvMPBj6tgsjiI4JJbW2Irj-sUW1stskQ25-G5cDRI-qoZFQTlvRvGVFR97arFD9gwAIB8Gfz4Sog-QC1wLDS3xStvygsCDabQmaF8JaE_zWbtJ7Izs7Jd45VOiI4CS_uZY5dsgODB5IqW1hwj-JY";
@@ -27,7 +27,9 @@ public class MyTestMethods { @@ -27,7 +27,9 @@ public class MyTestMethods {
27 public BusResult product_old() 27 public BusResult product_old()
28 { 28 {
29 long start = System.currentTimeMillis(); 29 long start = System.currentTimeMillis();
30 - String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <MSG> <META> <SNDR>zicheng</SNDR> \t\t<RCVR></RCVR> \t\t<DDTM>20200902164413</DDTM> \t\t<TYPE>E_zicheng</TYPE> \t\t<STYP>R_zicheng</STYP> \t\t<SEQN>本性难移</SEQN> \t\t<TOKN>江山易老</TOKN> \t\t<VSHT>V_zicheng</VSHT> \t\t<SERV>S_zicheng</SERV> \t</META> \t<BODY>中元节,即是鬼节</BODY> </MSG>"; 30 + String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <MSG> <META> <SNDR>zicheng</SNDR> \t\t<RCVR></RCVR> " +
  31 + "\t\t<DDTM>20200902164413</DDTM> \t\t<TYPE>E_zicheng</TYPE> \t\t<STYP>R_zicheng</STYP> \t\t<SEQN>本性难移</SEQN> \t\t<TOKN>江山易老</TOKN> " +
  32 + "\t\t<VSHT>V_zicheng</VSHT> \t\t<SERV>S_zicheng</SERV> \t</META> \t<BODY>你好啊,我的老BoBy</BODY> </MSG>";
31 33
32 MessageRequest messageRequest = new MessageRequest(); 34 MessageRequest messageRequest = new MessageRequest();
33 BusResult busResult = messageRequest.sendMessage(url_product_old, token, content); 35 BusResult busResult = messageRequest.sendMessage(url_product_old, token, content);
@@ -40,8 +42,8 @@ public class MyTestMethods { @@ -40,8 +42,8 @@ public class MyTestMethods {
40 { 42 {
41 long start = System.currentTimeMillis(); 43 long start = System.currentTimeMillis();
42 MessageRequest messageRequest = new MessageRequest(); 44 MessageRequest messageRequest = new MessageRequest();
43 - BusResult busResult = messageRequest.sendMessage(url_product_new, "S_zicheng", "V_zicheng", "E_zicheng", "R_zicheng", "江山易老,本性难移", "zicheng"  
44 - , "20200907164413", token, "序列号"); 45 + BusResult busResult = messageRequest.sendMessage(url_product_new, "S_zicheng", "V_zicheng", "E_zicheng", "R_zicheng", "待到重阳日,还来就菊花", "zicheng"
  46 + , "20200909164413", token, "序列号");
45 long end = System.currentTimeMillis(); 47 long end = System.currentTimeMillis();
46 System.out.println("发送一条参数消息,耗时:" + (end - start) + "毫秒"); 48 System.out.println("发送一条参数消息,耗时:" + (end - start) + "毫秒");
47 return busResult; 49 return busResult;
@@ -59,7 +61,7 @@ public class MyTestMethods { @@ -59,7 +61,7 @@ public class MyTestMethods {
59 61
60 public BusResult consumerMore() 62 public BusResult consumerMore()
61 { 63 {
62 - int num = 100; 64 + int num = 10000;
63 long start = System.currentTimeMillis(); 65 long start = System.currentTimeMillis();
64 MessageRequest messageRequest = new MessageRequest(); 66 MessageRequest messageRequest = new MessageRequest();
65 BusResult busResult = messageRequest.getMessageMore(url_consumer_more, token, "zicheng", "S_zicheng", 67 BusResult busResult = messageRequest.getMessageMore(url_consumer_more, token, "zicheng", "S_zicheng",
@@ -19,16 +19,15 @@ import java.util.concurrent.locks.ReentrantLock; @@ -19,16 +19,15 @@ import java.util.concurrent.locks.ReentrantLock;
19 public class Test2 { 19 public class Test2 {
20 public static void main(String[] args) throws IOException 20 public static void main(String[] args) throws IOException
21 { 21 {
22 - // 1031 15:45:58 15:48:57  
23 Test2 t2 = new Test2(); 22 Test2 t2 = new Test2();
24 t2.moreThread(); 23 t2.moreThread();
25 } 24 }
26 25
27 void moreThread() 26 void moreThread()
28 { 27 {
29 - Tickets thread = new Tickets();  
30 - 28 + long start = System.currentTimeMillis();
31 29
  30 + Tickets thread = new Tickets();
32 ExecutorService executorService = new ThreadPoolExecutor( 31 ExecutorService executorService = new ThreadPoolExecutor(
33 32, 64, 32 32, 64,
34 0L, 33 0L,
@@ -36,20 +35,29 @@ public class Test2 { @@ -36,20 +35,29 @@ public class Test2 {
36 new LinkedBlockingQueue<>(10), 35 new LinkedBlockingQueue<>(10),
37 Executors.defaultThreadFactory(), 36 Executors.defaultThreadFactory(),
38 new ThreadPoolExecutor.AbortPolicy()); 37 new ThreadPoolExecutor.AbortPolicy());
39 - for (int i = 0; i < 32; i++) { 38 + for (int i = 0; i < 20; i++) {
40 executorService.submit(thread); 39 executorService.submit(thread);
41 } 40 }
42 executorService.shutdown(); 41 executorService.shutdown();
  42 +
  43 + while (!executorService.isTerminated()) {
  44 +
  45 + }
  46 + long end = System.currentTimeMillis();
  47 + System.out.println("耗时:" + (end - start));
43 } 48 }
44 } 49 }
45 50
46 class Tickets implements Runnable { 51 class Tickets implements Runnable {
47 - private int ticket = 1000; 52 + private int ticket = 100;
  53 +
  54 + Lock lock = new ReentrantLock();
48 55
49 @Override 56 @Override
50 public void run() 57 public void run()
51 { 58 {
52 while (true) { 59 while (true) {
  60 + lock.lock();
53 try { 61 try {
54 if (ticket <= 0) { 62 if (ticket <= 0) {
55 break; 63 break;
@@ -58,9 +66,10 @@ class Tickets implements Runnable { @@ -58,9 +66,10 @@ class Tickets implements Runnable {
58 // 发送一条报文消息 66 // 发送一条报文消息
59 BusResult busResult = myTestMethods.product_old(); 67 BusResult busResult = myTestMethods.product_old();
60 System.out.println(Thread.currentThread().getName() + "发送了第" + ticket + "条消息"); 68 System.out.println(Thread.currentThread().getName() + "发送了第" + ticket + "条消息");
  69 + System.out.println(busResult);
61 ticket--; 70 ticket--;
62 } finally { 71 } finally {
63 - 72 + lock.unlock();
64 } 73 }
65 } 74 }
66 } 75 }
@@ -171,6 +171,4 @@ public class MessageRequest { @@ -171,6 +171,4 @@ public class MessageRequest {
171 BusResult result = new BusResult(true, code, msg, dataList); 171 BusResult result = new BusResult(true, code, msg, dataList);
172 return result; 172 return result;
173 } 173 }
174 -  
175 -  
176 } 174 }
@@ -88,9 +88,9 @@ public class OkHttpUtils { @@ -88,9 +88,9 @@ public class OkHttpUtils {
88 private Boolean isBlankUrl(String url) 88 private Boolean isBlankUrl(String url)
89 { 89 {
90 if (StringUtils.isBlank(url)) { 90 if (StringUtils.isBlank(url)) {
  91 + log.info("url is blank-->" + url);
91 return true; 92 return true;
92 } else { 93 } else {
93 - log.info("url is blank-->" + url);  
94 return false; 94 return false;
95 } 95 }
96 } 96 }
@@ -108,7 +108,6 @@ public class OkHttpUtils { @@ -108,7 +108,6 @@ public class OkHttpUtils {
108 } 108 }
109 } catch (Exception e) { 109 } catch (Exception e) {
110 log.error("request execute failure", e); 110 log.error("request execute failure", e);
111 - System.out.println("失败");  
112 } 111 }
113 return re; 112 return re;
114 } 113 }
  1 +F:\郑州商友\mywork\消息总线服务\message_bus_sdk\src\main\java\com\sunyo\wlpt\message\bus\sdk\App.java
  2 +F:\郑州商友\mywork\消息总线服务\message_bus_sdk\src\main\java\com\sunyo\wlpt\message\bus\sdk\utils\GsonUtil.java
  3 +F:\郑州商友\mywork\消息总线服务\message_bus_sdk\src\main\java\com\sunyo\wlpt\message\bus\sdk\request\MessageRequest.java
  4 +F:\郑州商友\mywork\消息总线服务\message_bus_sdk\src\main\java\com\sunyo\wlpt\message\bus\sdk\domain\ExitThreadPoolFactory.java
  5 +F:\郑州商友\mywork\消息总线服务\message_bus_sdk\src\main\java\com\sunyo\wlpt\message\bus\sdk\response\BusResult.java
  6 +F:\郑州商友\mywork\消息总线服务\message_bus_sdk\src\main\java\com\sunyo\wlpt\message\bus\sdk\utils\OkHttpUtils.java
  7 +F:\郑州商友\mywork\消息总线服务\message_bus_sdk\src\main\java\com\sunyo\wlpt\message\bus\sdk\domain\ExitThreadFactory.java
  8 +F:\郑州商友\mywork\消息总线服务\message_bus_sdk\src\main\java\com\sunyo\wlpt\message\bus\sdk\response\ResultJson.java
  9 +F:\郑州商友\mywork\消息总线服务\message_bus_sdk\src\main\java\com\sunyo\wlpt\message\bus\sdk\request\BusMessage.java