You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/11/08 16:13:17 UTC

[GitHub] [dubbo] luger1990 opened a new issue, #10897: 如果正确的使用dubbo3的triple协议上传文件/图片

luger1990 opened a new issue, #10897:
URL: https://github.com/apache/dubbo/issues/10897

   grpc有流式服务和非流式服务,上传文件使用triple协议应该怎么选择呢?选择流式服务肯定是没问题的,但是调用方用起来太难受。下面是例子
   proto定义
   ```
   syntax = "proto3";
   
   option java_multiple_files = true;
   option java_package = "com.nct.player.upload";
   option java_outer_classname = "NctFileUpload";
   option objc_class_prefix = "HLW";
   
   package com.nct.player.upload;
   
   service NctFileUploadRpc {
     rpc upload(stream NctFileUploadParam) returns (NctFileUploadDto);
     rpc upload1(NctFileUploadParam) returns (NctFileUploadDto);
   }
   
   //Upload
   message NctFileUploadParam {
     string fileName = 1;
     bytes stream = 2;
   }
   
   message NctFileUploadDto {
     string filePath = 1;
   }
   ```
   
   实现类:
   ```
   @DubboService
   public class NctFileUploadService implements NctFileUploadRpc {
       @Override
       public NctFileUploadDto upload1(NctFileUploadParam nctFileUploadParam) {
           ByteString byteString = nctFileUploadParam.getStream();
           byte[] bytes = byteString.toByteArray();
           ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
           MkFileUtil.writeFromStream(byteArrayInputStream, "c:/a.jpg");
           return NctFileUploadDto.newBuilder().build();
       }
   
       @Override
       public CompletableFuture<NctFileUploadDto> upload1Async(NctFileUploadParam request) {
           return NctFileUploadRpc.super.upload1Async(request);
       }
   
       @Override
       public void upload1(NctFileUploadParam request, StreamObserver<NctFileUploadDto> responseObserver) {
           NctFileUploadRpc.super.upload1(request, responseObserver);
       }
   
       @Override
       public StreamObserver<NctFileUploadParam> upload(StreamObserver<NctFileUploadDto> responseObserver) {
           return new StreamObserver<NctFileUploadParam>() {
               @Override
               public void onNext(NctFileUploadParam nctFileUploadParam) {
                   ByteString byteString = nctFileUploadParam.getStream();
                   byte[] bytes = byteString.toByteArray();
                   ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
                   MkFileUtil.writeFromStream(byteArrayInputStream, "c:/a.jpg");
   
               }
   
               @Override
               public void onError(Throwable t) {
                   MkLogUtil.error(t);
               }
   
               @Override
               public void onCompleted() {
                   responseObserver.onNext(NctFileUploadDto.newBuilder()
                           .setFilePath("test")
                           .build());
                   responseObserver.onCompleted();
               }
           };
       }
   }
   ```
   
   下面说一下我的问题。
   如果调用upload的话需要构建StreamObserver对象,对调用方特别不友好。
   如果调用upload1的话通过NctFileUploadParam传参即可,但是不确定有没有性能问题。
   请指教。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] AlbumenJ commented on issue #10897: 如果正确的使用dubbo3的triple协议上传文件/图片

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #10897:
URL: https://github.com/apache/dubbo/issues/10897#issuecomment-1308092110

   @EarthChen PTAL


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] EarthChen commented on issue #10897: 如果正确的使用dubbo3的triple协议上传文件/图片

Posted by GitBox <gi...@apache.org>.
EarthChen commented on issue #10897:
URL: https://github.com/apache/dubbo/issues/10897#issuecomment-1314663295

   > > 如果 dubbo 帮用户对大对象自动拆成多个小对象,那在接收端合并的规则又是什么呢 ,框架很难帮用户决定怎么拆分 怎么合并,这类场景还是倾向用户自己使用 stream 进行包装
   > 
   > 如果我不用stream直接用byte[]数组传递 并且用grpc或者triple协议会有问题吗?
   
   其实没什么问题,这就好比你使用 http 协议单文件上传,只是在容易因为波动失败而已


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] EarthChen commented on issue #10897: 如果正确的使用dubbo3的triple协议上传文件/图片

Posted by GitBox <gi...@apache.org>.
EarthChen commented on issue #10897:
URL: https://github.com/apache/dubbo/issues/10897#issuecomment-1308113858

   如果 dubbo 帮用户对大对象自动拆成多个小对象,那在接收端合并的规则又是什么呢 ,框架很难帮用户决定怎么拆分 怎么合并,这类场景还是倾向用户自己使用 stream 进行包装


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] luger1990 commented on issue #10897: 如果正确的使用dubbo3的triple协议上传文件/图片

Posted by GitBox <gi...@apache.org>.
luger1990 commented on issue #10897:
URL: https://github.com/apache/dubbo/issues/10897#issuecomment-1313582384

   > 如果 dubbo 帮用户对大对象自动拆成多个小对象,那在接收端合并的规则又是什么呢 ,框架很难帮用户决定怎么拆分 怎么合并,这类场景还是倾向用户自己使用 stream 进行包装
   
   如果我不用stream直接用byte[]数组传递 并且用grpc或者triple协议会有问题吗?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] luger1990 closed issue #10897: 如果正确的使用dubbo3的triple协议上传文件/图片

Posted by GitBox <gi...@apache.org>.
luger1990 closed issue #10897: 如果正确的使用dubbo3的triple协议上传文件/图片
URL: https://github.com/apache/dubbo/issues/10897


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] luger1990 commented on issue #10897: 如果正确的使用dubbo3的triple协议上传文件/图片

Posted by GitBox <gi...@apache.org>.
luger1990 commented on issue #10897:
URL: https://github.com/apache/dubbo/issues/10897#issuecomment-1314856578

   > > > 如果 dubbo 帮用户对大对象自动拆成多个小对象,那在接收端合并的规则又是什么呢 ,框架很难帮用户决定怎么拆分 怎么合并,这类场景还是倾向用户自己使用 stream 进行包装
   > > 
   > > 
   > > 如果我不用stream直接用byte[]数组传递 并且用grpc或者triple协议会有问题吗?
   > 
   > 其实没什么问题,这就好比你使用 http 协议单文件上传,只是在容易因为波动失败而已
   
   明白了 多谢。 我做一些测试。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org