[ 
https://issues.apache.org/jira/browse/SCB-138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16305896#comment-16305896
 ] 

ASF GitHub Bot commented on SCB-138:
------------------------------------

eric-lee-ltk commented on a change in pull request #93: [WIP]SCB-138 replace 
thrift with grpc
URL: 
https://github.com/apache/incubator-servicecomb-saga/pull/93#discussion_r159018161
 
 

 ##########
 File path: 
omega/omega-connector/omega-connector-grpc/src/main/java/io/servicecomb/saga/omega/connector/grpc/GrpcClientMessageSender.java
 ##########
 @@ -0,0 +1,61 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ */
+
+package io.servicecomb.saga.omega.connector.grpc;
+
+import com.google.protobuf.ByteString;
+
+import io.servicecomb.saga.omega.transaction.MessageSender;
+import io.servicecomb.saga.omega.transaction.MessageSerializer;
+import io.servicecomb.saga.omega.transaction.TxEvent;
+import io.servicecomb.saga.pack.contract.grpc.GrpcTxEvent;
+import io.servicecomb.saga.pack.contract.grpc.GrpcTxEvent.Builder;
+import io.servicecomb.saga.pack.contract.grpc.GrpcTxEventEndpoint;
+
+public class GrpcClientMessageSender implements MessageSender {
+
+  private final GrpcTxEventEndpoint eventService;
+
+  private final MessageSerializer serializer;
+
+  public GrpcClientMessageSender(GrpcTxEventEndpoint eventService, 
MessageSerializer serializer) {
+    this.eventService = eventService;
+    this.serializer = serializer;
+  }
+
+  @Override
+  public void send(TxEvent event) {
+    eventService.reportEvent(convertEvent(event));
+  }
+
+  private GrpcTxEvent convertEvent(TxEvent event) {
+    ByteString payloads = 
ByteString.copyFrom(serializer.serialize(event.payloads()));
+    Builder builder = GrpcTxEvent.newBuilder()
+        .setTimestamp(event.timestamp())
+        .setGlobalTxId(event.globalTxId())
+        .setLocalTxId(event.localTxId())
+        .setType(event.type())
+        .setPayloads(payloads);
+    if (event.parentTxId() != null) {
+      builder.setParentTxId(event.parentTxId());
 
 Review comment:
   set to null will throw an exception. It will set to "" by default.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [pack] omega's callback about transaction state
> -----------------------------------------------
>
>                 Key: SCB-138
>                 URL: https://issues.apache.org/jira/browse/SCB-138
>             Project: Apache ServiceComb
>          Issue Type: New Feature
>          Components: Saga
>            Reporter: Eric Lee
>            Assignee: Eric Lee
>             Fix For: java-chassis-1.0.0-m1
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> as a dev, i want to register callback function in the server side, so the 
> server can send messages back to the client directly instead of establishing 
> a new connection to the exact client with its corresponding uri.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to