赞
踩
responseObserver.onNext(DeductReply.newBuilder()
.setCode(code)
.setMessage(message)
.build());
}
@Override
public void onError(Throwable t) {
log.error(“批量减扣库存异常”, t);
}
@Override
public void onCompleted() {
log.info(“批量减扣库存完成,共计[{}]件商品”, totalCount);
responseObserver.onCompleted();
}
};
}
}
plugins {
id ‘org.springframework.boot’
}
dependencies {
implementation ‘org.projectlombok:lombok’
implementation ‘org.springframework.boot:spring-boot-starter’
implementation ‘org.springframework.boot:spring-boot-starter-web’
implementation ‘net.devh:grpc-client-spring-boot-starter’
implementation project(’:grpc-lib’)
}
server:
port: 8082
spring:
application:
name: double-stream-client-side
grpc:
client:
double-stream-server-side:
address: ‘static://127.0.0.1:9901’
enableKeepAlive: true
keepAliveWithoutCalls: true
negotiationType: plaintext
启动类DoubleStreamClientSideApplication.java的代码就不贴了,普通的springboot启动类而已;
正常情况下我们都是用StreamObserver处理服务端响应,这里由于是异步响应,需要额外的方法从StreamObserver中取出业务数据,于是定一个新接口
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。