From 55cf7944eda8f63c079226a9ad7cf6d9944450eb Mon Sep 17 00:00:00 2001 From: crusader Date: Sat, 9 Dec 2017 17:45:07 +0900 Subject: [PATCH] JSON RPC Protocol --- .../commons/model/PublishMessage.java | 32 ++++++++++++++++--- .../redis/service/RedisMessagePublisher.java | 1 - src/main/resources/local/database.properties | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/loafle/overflow/commons/model/PublishMessage.java b/src/main/java/com/loafle/overflow/commons/model/PublishMessage.java index 1f7d06c..17ecda5 100644 --- a/src/main/java/com/loafle/overflow/commons/model/PublishMessage.java +++ b/src/main/java/com/loafle/overflow/commons/model/PublishMessage.java @@ -31,20 +31,43 @@ public class PublishMessage { } public static class PublishMessageBody { - private String method; - private List params; + private String jsonrpc = "2.0"; + private PublishMessageBodyNotification result; public PublishMessageBody() { + this.result = new PublishMessageBodyNotification(); } public PublishMessageBody(String method) { - this.method = method; + this(); + this.result.setMethod(method); } public PublishMessageBody(String method, List params) { this(method); - this.params = params; + this.result.setParams(params); } + public String getJsonrpc() { + return jsonrpc; + } + + public void setJsonrpc(String jsonrpc) { + this.jsonrpc = jsonrpc; + } + + public PublishMessageBodyNotification getResult() { + return result; + } + + public void setResult(PublishMessageBodyNotification result) { + this.result = result; + } + } + + public static class PublishMessageBodyNotification { + private String method; + private List params; + public String getMethod() { return method; } @@ -67,5 +90,6 @@ public class PublishMessage { } this.params.add(param); } + } } diff --git a/src/main/java/com/loafle/overflow/redis/service/RedisMessagePublisher.java b/src/main/java/com/loafle/overflow/redis/service/RedisMessagePublisher.java index b6a4233..b735d9b 100644 --- a/src/main/java/com/loafle/overflow/redis/service/RedisMessagePublisher.java +++ b/src/main/java/com/loafle/overflow/redis/service/RedisMessagePublisher.java @@ -79,7 +79,6 @@ public class RedisMessagePublisher implements MessagePublisher { return results; } - protected void publish(final String channel, PublishMessage message, final String method, Object... params) { ChannelTopic topic = this.topics.get(channel); message.setMessage(new PublishMessage.PublishMessageBody(method, this.getMessageBody(params))); diff --git a/src/main/resources/local/database.properties b/src/main/resources/local/database.properties index 0b6c454..e8c1188 100644 --- a/src/main/resources/local/database.properties +++ b/src/main/resources/local/database.properties @@ -1,4 +1,4 @@ -datasource.url=jdbc:postgresql://192.168.1.209:5432/overflow +datasource.url=jdbc:postgresql://192.168.1.50:5432/overflow datasource.username=overflow datasource.password=qwer5795 datasource.driver-class-name=org.postgresql.Driver