作者 王勇

收消息,基本完善

  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="ProjectInspectionProfilesVisibleTreeState">
  4 + <entry key="Project Default">
  5 + <profile-state>
  6 + <expanded-state>
  7 + <State />
  8 + <State>
  9 + <id>Java</id>
  10 + </State>
  11 + <State>
  12 + <id>Serialization issuesJava</id>
  13 + </State>
  14 + </expanded-state>
  15 + <selected-state>
  16 + <State>
  17 + <id>SerializableHasSerialVersionUIDField</id>
  18 + </State>
  19 + </selected-state>
  20 + </profile-state>
  21 + </entry>
  22 + </component>
  23 +</project>
  1 +# Default ignored files
  2 +/shelf/
  3 +/workspace.xml
  4 +# Datasource local storage ignored files
  5 +/dataSources/
  6 +/dataSources.local.xml
  7 +# Editor-based HTTP Client requests
  8 +/httpRequests/
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="CompilerConfiguration">
  4 + <annotationProcessing>
  5 + <profile name="Maven default annotation processors profile" enabled="true">
  6 + <sourceOutputDir name="target/generated-sources/annotations" />
  7 + <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
  8 + <outputRelativeToContentRoot value="true" />
  9 + <module name="message_bus_sdk" />
  10 + </profile>
  11 + </annotationProcessing>
  12 + </component>
  13 + <component name="JavacSettings">
  14 + <option name="ADDITIONAL_OPTIONS_OVERRIDE">
  15 + <module name="message_bus_sdk" options="-parameters" />
  16 + </option>
  17 + </component>
  18 +</project>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
  4 + <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
  5 + <file url="PROJECT" charset="UTF-8" />
  6 + </component>
  7 +</project>
  1 +<component name="InspectionProjectProfileManager">
  2 + <profile version="1.0">
  3 + <option name="myName" value="Project Default" />
  4 + <inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
  5 + <option name="TOP_LEVEL_CLASS_OPTIONS">
  6 + <value>
  7 + <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
  8 + <option name="REQUIRED_TAGS" value="" />
  9 + </value>
  10 + </option>
  11 + <option name="INNER_CLASS_OPTIONS">
  12 + <value>
  13 + <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
  14 + <option name="REQUIRED_TAGS" value="" />
  15 + </value>
  16 + </option>
  17 + <option name="METHOD_OPTIONS">
  18 + <value>
  19 + <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
  20 + <option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
  21 + </value>
  22 + </option>
  23 + <option name="FIELD_OPTIONS">
  24 + <value>
  25 + <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
  26 + <option name="REQUIRED_TAGS" value="" />
  27 + </value>
  28 + </option>
  29 + <option name="IGNORE_DEPRECATED" value="false" />
  30 + <option name="IGNORE_JAVADOC_PERIOD" value="true" />
  31 + <option name="IGNORE_DUPLICATED_THROWS" value="false" />
  32 + <option name="IGNORE_POINT_TO_ITSELF" value="false" />
  33 + <option name="myAdditionalJavadocTags" value="date" />
  34 + </inspection_tool>
  35 + </profile>
  36 +</component>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="RemoteRepositoriesConfiguration">
  4 + <remote-repository>
  5 + <option name="id" value="central" />
  6 + <option name="name" value="Central Repository" />
  7 + <option name="url" value="http://maven.aliyun.com/nexus/content/groups/public/" />
  8 + </remote-repository>
  9 + <remote-repository>
  10 + <option name="id" value="central" />
  11 + <option name="name" value="Maven Central repository" />
  12 + <option name="url" value="https://repo1.maven.org/maven2" />
  13 + </remote-repository>
  14 + <remote-repository>
  15 + <option name="id" value="jboss.community" />
  16 + <option name="name" value="JBoss Community repository" />
  17 + <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
  18 + </remote-repository>
  19 + </component>
  20 +</project>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="ExternalStorageConfigurationManager" enabled="true" />
  4 + <component name="MavenProjectsManager">
  5 + <option name="originalFiles">
  6 + <list>
  7 + <option value="$PROJECT_DIR$/pom.xml" />
  8 + </list>
  9 + </option>
  10 + </component>
  11 + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
  12 + <output url="file://$PROJECT_DIR$/out" />
  13 + </component>
  14 +</project>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="VcsDirectoryMappings">
  4 + <mapping directory="$PROJECT_DIR$" vcs="Git" />
  5 + </component>
  6 +</project>
  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
@@ -12,6 +12,13 @@ @@ -12,6 +12,13 @@
12 <!-- FIXME change it to the project's website --> 12 <!-- FIXME change it to the project's website -->
13 <url>http://www.example.com</url> 13 <url>http://www.example.com</url>
14 14
  15 + <parent>
  16 + <groupId>org.springframework.boot</groupId>
  17 + <artifactId>spring-boot-starter-parent</artifactId>
  18 + <version>2.2.5.RELEASE</version>
  19 + </parent>
  20 +
  21 +
15 <properties> 22 <properties>
16 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 23 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
17 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 24 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -20,6 +27,21 @@ @@ -20,6 +27,21 @@
20 </properties> 27 </properties>
21 28
22 <dependencies> 29 <dependencies>
  30 + <dependency>
  31 + <groupId>org.springframework.boot</groupId>
  32 + <artifactId>spring-boot-starter</artifactId>
  33 + </dependency>
  34 +
  35 + <dependency>
  36 + <groupId>org.springframework.boot</groupId>
  37 + <artifactId>spring-boot-starter-web</artifactId>
  38 + </dependency>
  39 +
  40 + <dependency>
  41 + <groupId>org.springframework.boot</groupId>
  42 + <artifactId>spring-boot-starter-log4j</artifactId>
  43 + <version>1.3.8.RELEASE</version>
  44 + </dependency>
23 45
24 <dependency> 46 <dependency>
25 <groupId>com.squareup.okhttp3</groupId> 47 <groupId>com.squareup.okhttp3</groupId>
@@ -77,9 +99,6 @@ @@ -77,9 +99,6 @@
77 <artifactId>slf4j-api</artifactId> 99 <artifactId>slf4j-api</artifactId>
78 <version>1.7.30</version> 100 <version>1.7.30</version>
79 </dependency> 101 </dependency>
80 -  
81 -  
82 -  
83 </dependencies> 102 </dependencies>
84 103
85 <build> 104 <build>
@@ -5,15 +5,20 @@ import com.sunyo.wlpt.message.bus.sdk.response.BusResult; @@ -5,15 +5,20 @@ import com.sunyo.wlpt.message.bus.sdk.response.BusResult;
5 5
6 import java.io.IOException; 6 import java.io.IOException;
7 7
  8 +
8 /** 9 /**
9 - * Hello world! 10 + * @author 子诚
10 */ 11 */
11 public class App { 12 public class App {
12 - public static void main(String[] args) 13 + public static void main(String[] args) throws IOException
13 { 14 {
14 MessageRequest request = new MessageRequest(); 15 MessageRequest request = new MessageRequest();
15 - BusResult result = request.getMessageOne("zicheng", "S_zicheng", 16 + BusResult resultOne = request.getMessageOne("zicheng", "S_zicheng",
16 "V_zicheng", "V_zicheng_zicheng_R"); 17 "V_zicheng", "V_zicheng_zicheng_R");
17 - System.out.println(result); 18 + BusResult resultMore = request.getMessageMore("zicheng", "S_zicheng",
  19 + "V_zicheng", "V_zicheng_zicheng_R", 5);
  20 +
  21 + System.out.println(resultOne);
  22 + System.out.println(resultMore);
18 } 23 }
19 } 24 }
@@ -6,8 +6,11 @@ import com.sunyo.wlpt.message.bus.sdk.utils.OkHttpUtils; @@ -6,8 +6,11 @@ import com.sunyo.wlpt.message.bus.sdk.utils.OkHttpUtils;
6 import okhttp3.MediaType; 6 import okhttp3.MediaType;
7 7
8 8
  9 +import java.io.FileInputStream;
  10 +import java.io.FileNotFoundException;
9 import java.io.IOException; 11 import java.io.IOException;
10 import java.util.HashMap; 12 import java.util.HashMap;
  13 +import java.util.Properties;
11 14
12 /** 15 /**
13 * @author 子诚 16 * @author 子诚
@@ -16,35 +19,73 @@ import java.util.HashMap; @@ -16,35 +19,73 @@ import java.util.HashMap;
16 */ 19 */
17 public class BusMessage { 20 public class BusMessage {
18 21
19 - private static final String URL_CONSUMER_ONE = "http://192.168.1.33:9032/bus/rabbit/consumer_one";  
20 - private static final String URL_CONSUMER_MORE = "http://192.168.1.33:9032/bus/rabbit/consumer_more";  
21 - 22 + /**
  23 + * 指定队列,接收一条消息
  24 + *
  25 + * @param RUSR 接收者
  26 + * @param SERV 服务器名称
  27 + * @param VSHT 虚拟主机名称
  28 + * @param RCVR 队列名称
  29 + * @return
  30 + * @throws IOException
  31 + */
  32 + public static ResultJson consumerOne(String RUSR, String SERV, String VSHT, String RCVR) throws IOException
  33 + {
  34 + HashMap<String, Object> params = new HashMap<>();
  35 + params.put("RUSR", RUSR);
  36 + params.put("SERV", SERV);
  37 + params.put("VSHT", VSHT);
  38 + params.put("RCVR", RCVR);
22 39
23 - private static final MediaType MEDIA_TYPE_TEXT = MediaType.parse("application/x-www-form-urlencoded; charset=utf-8"); 40 + OkHttpUtils okHttp = new OkHttpUtils();
  41 + String url_consumer_one = getUrl("URL_CONSUMER_ONE");
  42 + String json = okHttp.doGet(url_consumer_one, params);
  43 + ResultJson result = GsonUtil.GsonToBean(json, ResultJson.class);
  44 + return result;
  45 + }
24 46
25 /** 47 /**
26 - * 指定队列,消费一条消息 48 + * 指定队列,接收多条消息
27 * 49 *
28 * @param RUSR 接收者 50 * @param RUSR 接收者
29 * @param SERV 服务器名称 51 * @param SERV 服务器名称
30 * @param VSHT 虚拟主机名称 52 * @param VSHT 虚拟主机名称
31 * @param RCVR 队列名称 53 * @param RCVR 队列名称
  54 + * @param CUNT 接收消息的数量
32 * @return 55 * @return
33 * @throws IOException 56 * @throws IOException
34 */ 57 */
35 - public static ResultJson consumerOne(String RUSR, String SERV, String VSHT, String RCVR) 58 + public static ResultJson consumerMore(String RUSR, String SERV, String VSHT, String RCVR, Integer CUNT) throws IOException
36 { 59 {
37 - HashMap<String, String> params = new HashMap<>(); 60 + HashMap<String, Object> params = new HashMap<>();
38 params.put("RUSR", RUSR); 61 params.put("RUSR", RUSR);
39 params.put("SERV", SERV); 62 params.put("SERV", SERV);
40 params.put("VSHT", VSHT); 63 params.put("VSHT", VSHT);
41 params.put("RCVR", RCVR); 64 params.put("RCVR", RCVR);
  65 + params.put("CUNT", CUNT);
42 66
43 OkHttpUtils okHttp = new OkHttpUtils(); 67 OkHttpUtils okHttp = new OkHttpUtils();
44 - String json = okHttp.doGet(URL_CONSUMER_ONE, params); 68 + String url_consumer_more = getUrl("URL_CONSUMER_MORE");
  69 + String json = okHttp.doGet(url_consumer_more, params);
45 ResultJson result = GsonUtil.GsonToBean(json, ResultJson.class); 70 ResultJson result = GsonUtil.GsonToBean(json, ResultJson.class);
46 return result; 71 return result;
47 } 72 }
48 73
49 74
  75 + /**
  76 + * 根据url名称,动态获取url
  77 + *
  78 + * @param urlName url名称
  79 + * @return url信息
  80 + * @throws IOException
  81 + */
  82 + public static String getUrl(String urlName) throws IOException
  83 + {
  84 + Properties properties = new Properties();
  85 + FileInputStream fis = new FileInputStream("config\\url.properties");
  86 + properties.load(fis);
  87 + fis.close();
  88 + String url = properties.getProperty(urlName);
  89 + return url;
  90 + }
50 } 91 }
@@ -3,6 +3,9 @@ package com.sunyo.wlpt.message.bus.sdk.request; @@ -3,6 +3,9 @@ package com.sunyo.wlpt.message.bus.sdk.request;
3 import com.sunyo.wlpt.message.bus.sdk.response.BusResult; 3 import com.sunyo.wlpt.message.bus.sdk.response.BusResult;
4 import com.sunyo.wlpt.message.bus.sdk.response.ResultJson; 4 import com.sunyo.wlpt.message.bus.sdk.response.ResultJson;
5 5
  6 +import java.io.IOException;
  7 +import java.util.List;
  8 +
6 /** 9 /**
7 * @author 子诚 10 * @author 子诚
8 * Description: 11 * Description:
@@ -21,7 +24,7 @@ public class MessageRequest { @@ -21,7 +24,7 @@ public class MessageRequest {
21 * @param RCVR 接收队列名称 24 * @param RCVR 接收队列名称
22 * @return 25 * @return
23 */ 26 */
24 - public BusResult getMessageOne(String RUSR, String SERV, String VSHT, String RCVR) 27 + public BusResult getMessageOne(String RUSR, String SERV, String VSHT, String RCVR) throws IOException
25 { 28 {
26 ResultJson resultJson = BusMessage.consumerOne(RUSR, SERV, VSHT, RCVR); 29 ResultJson resultJson = BusMessage.consumerOne(RUSR, SERV, VSHT, RCVR);
27 if (resultJson == null) { 30 if (resultJson == null) {
@@ -38,4 +41,23 @@ public class MessageRequest { @@ -38,4 +41,23 @@ public class MessageRequest {
38 BusResult result = new BusResult(true, code, msg, data); 41 BusResult result = new BusResult(true, code, msg, data);
39 return result; 42 return result;
40 } 43 }
  44 +
  45 +
  46 + public BusResult getMessageMore(String RUSR, String SERV, String VSHT, String RCVR, Integer CUNT) throws IOException
  47 + {
  48 + ResultJson resultJson = BusMessage.consumerMore(RUSR, SERV, VSHT, RCVR, CUNT);
  49 + if (resultJson == null) {
  50 +
  51 + }
  52 + String code = resultJson.getCode();
  53 + String msg = resultJson.getMsg();
  54 + if (!SUCCESS_ONE_CODE.equals(resultJson.getCode())) {
  55 + String resultMessage = "错误代码:" + code + ";错误信息:" + msg;
  56 + BusResult errorResult = new BusResult(false, code, resultMessage);
  57 + return errorResult;
  58 + }
  59 + List<String> dataList = (List<String>) resultJson.getData();
  60 + BusResult result = new BusResult(true, code, msg, dataList);
  61 + return result;
  62 + }
41 } 63 }
@@ -108,4 +108,16 @@ public class BusResult { @@ -108,4 +108,16 @@ public class BusResult {
108 { 108 {
109 this.dataList = dataList; 109 this.dataList = dataList;
110 } 110 }
  111 +
  112 + @Override
  113 + public String toString()
  114 + {
  115 + return "BusResult{" +
  116 + "isOk=" + isOk +
  117 + ", code='" + code + '\'' +
  118 + ", message='" + message + '\'' +
  119 + ", data='" + data + '\'' +
  120 + ", dataList=" + dataList +
  121 + '}';
  122 + }
111 } 123 }
1 package com.sunyo.wlpt.message.bus.sdk.utils; 1 package com.sunyo.wlpt.message.bus.sdk.utils;
2 2
3 -import lombok.extern.slf4j.Slf4j;  
4 import okhttp3.*; 3 import okhttp3.*;
5 import org.apache.commons.lang3.StringUtils; 4 import org.apache.commons.lang3.StringUtils;
  5 +import org.apache.log4j.Logger;
6 6
7 7
8 import java.net.URLEncoder; 8 import java.net.URLEncoder;
@@ -15,8 +15,8 @@ import java.util.concurrent.TimeUnit; @@ -15,8 +15,8 @@ import java.util.concurrent.TimeUnit;
15 * Description: 15 * Description:
16 * 时间:2020/9/3 15:22 16 * 时间:2020/9/3 15:22
17 */ 17 */
18 -@Slf4j  
19 public class OkHttpUtils { 18 public class OkHttpUtils {
  19 + private static Logger log = Logger.getLogger(OkHttpUtils.class);
20 20
21 private static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8"); 21 private static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
22 private static final MediaType MEDIA_TYPE_TEXT = MediaType.parse("application/x-www-form-urlencoded; charset=utf-8"); 22 private static final MediaType MEDIA_TYPE_TEXT = MediaType.parse("application/x-www-form-urlencoded; charset=utf-8");
@@ -57,7 +57,7 @@ public class OkHttpUtils { @@ -57,7 +57,7 @@ public class OkHttpUtils {
57 return commonRequest(request); 57 return commonRequest(request);
58 } 58 }
59 59
60 - public String doGet(String url, HashMap<String, String> params) 60 + public String doGet(String url, HashMap<String, Object> params)
61 { 61 {
62 if (isBlankUrl(url)) { 62 if (isBlankUrl(url)) {
63 return null; 63 return null;
@@ -102,9 +102,9 @@ public class OkHttpUtils { @@ -102,9 +102,9 @@ public class OkHttpUtils {
102 Response response = call.execute(); 102 Response response = call.execute();
103 if (response.isSuccessful()) { 103 if (response.isSuccessful()) {
104 re = response.body().string(); 104 re = response.body().string();
105 - log.info("request url:{};response:{}", request.url().toString(), re); 105 +// log.info("request url:{};response:{}", request.url().toString(), re);
106 } else { 106 } else {
107 - log.info("request failure url:{};message:{}", request.url().toString(), response.message()); 107 +// log.info("request failure url:{};message:{}", request.url().toString(), response.message());
108 } 108 }
109 } catch (Exception e) { 109 } catch (Exception e) {
110 log.error("request execute failure", e); 110 log.error("request execute failure", e);
@@ -142,7 +142,7 @@ public class OkHttpUtils { @@ -142,7 +142,7 @@ public class OkHttpUtils {
142 return request; 142 return request;
143 } 143 }
144 144
145 - private Request getRequestForGet(String url, HashMap<String, String> params) 145 + private Request getRequestForGet(String url, HashMap<String, Object> params)
146 { 146 {
147 Request request = new Request.Builder() 147 Request request = new Request.Builder()
148 .url(getUrlStringForGet(url, params)) 148 .url(getUrlStringForGet(url, params))
@@ -158,15 +158,20 @@ public class OkHttpUtils { @@ -158,15 +158,20 @@ public class OkHttpUtils {
158 return request; 158 return request;
159 } 159 }
160 160
161 - private String getUrlStringForGet(String url, HashMap<String, String> params) 161 + private String getUrlStringForGet(String url, HashMap<String, Object> params)
162 { 162 {
163 StringBuilder urlBuilder = new StringBuilder(); 163 StringBuilder urlBuilder = new StringBuilder();
164 urlBuilder.append(url); 164 urlBuilder.append(url);
165 urlBuilder.append("?"); 165 urlBuilder.append("?");
166 if (params != null && params.size() > 0) { 166 if (params != null && params.size() > 0) {
167 - for (Map.Entry<String, String> entry : params.entrySet()) { 167 + for (Map.Entry<String, Object> entry : params.entrySet()) {
168 try { 168 try {
169 - urlBuilder.append("&").append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), "UTF-8")); 169 +
  170 + urlBuilder.append("&").append(entry.getKey()).append("=").append(
  171 + "CUNT".equals(entry.getKey())
  172 + ? entry.getValue()
  173 + : URLEncoder.encode((String) entry.getValue(), "UTF-8")
  174 + );
170 } catch (Exception e) { 175 } catch (Exception e) {
171 urlBuilder.append("&").append(entry.getKey()).append("=").append(entry.getValue()); 176 urlBuilder.append("&").append(entry.getKey()).append("=").append(entry.getValue());
172 } 177 }