mirror of
https://gitee.com/san-bing/JChargePointProtocol
synced 2026-05-04 18:09:54 +08:00
grpc 实现
This commit is contained in:
@@ -4,10 +4,11 @@
|
||||
*/
|
||||
package sanbing.jcpp.infrastructure.queue;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ProtoQueueMsg<T extends com.google.protobuf.GeneratedMessageV3> implements QueueMsg {
|
||||
public class ProtoQueueMsg<T extends GeneratedMessage> implements QueueMsg {
|
||||
|
||||
private final String key;
|
||||
protected final T value;
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
@@ -42,15 +41,18 @@ public class DefaultServiceInfoProvider implements ServiceInfoProvider {
|
||||
private ServiceInfo serviceInfo;
|
||||
|
||||
@Getter
|
||||
private String serviceWebapiEndpoint;
|
||||
private String hostAddress;
|
||||
|
||||
@Getter
|
||||
@Value("${server.port}")
|
||||
private String webapiPort;
|
||||
private int restPort;
|
||||
|
||||
@Getter
|
||||
@Value("${service.protocol.rpc.port:9090}")
|
||||
private int grpcPort;
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws UnknownHostException {
|
||||
|
||||
|
||||
if (!StringUtils.hasText(this.serviceId)) {
|
||||
try {
|
||||
this.serviceId = InetAddress.getLocalHost().getHostName();
|
||||
@@ -58,10 +60,11 @@ public class DefaultServiceInfoProvider implements ServiceInfoProvider {
|
||||
this.serviceId = RandomStringUtils.randomAlphabetic(10);
|
||||
}
|
||||
}
|
||||
log.info("Current Service ID: {}", this.serviceId);
|
||||
log.info("Current Service ID: {}", serviceId);
|
||||
|
||||
serviceWebapiEndpoint = InetAddress.getLocalHost().getHostAddress() + ":" + webapiPort;
|
||||
log.info("Current Service HostAddress: {}", this.serviceWebapiEndpoint);
|
||||
hostAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
|
||||
log.info("Current Service HostAddress: {}, RestPort:{}, GrpcPort:{}", hostAddress, restPort, grpcPort);
|
||||
if (serviceType.equalsIgnoreCase("monolith")) {
|
||||
serviceTypes = List.of(ServiceType.values());
|
||||
} else {
|
||||
@@ -86,7 +89,7 @@ public class DefaultServiceInfoProvider implements ServiceInfoProvider {
|
||||
public ServiceInfo generateNewServiceInfoWithCurrentSystemInfo() {
|
||||
ServiceInfo.Builder builder = ServiceInfo.newBuilder()
|
||||
.setServiceId(serviceId)
|
||||
.addAllServiceTypes(serviceTypes.stream().map(ServiceType::name).collect(Collectors.toList()))
|
||||
.addAllServiceTypes(serviceTypes.stream().map(ServiceType::name).toList())
|
||||
.setSystemInfo(getCurrentSystemInfoProto());
|
||||
return serviceInfo = builder.build();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,11 @@ import sanbing.jcpp.proto.gen.ClusterProto;
|
||||
public interface ServiceInfoProvider {
|
||||
String getServiceId();
|
||||
|
||||
String getServiceWebapiEndpoint();
|
||||
String getHostAddress();
|
||||
|
||||
int getRestPort();
|
||||
|
||||
int getGrpcPort();
|
||||
|
||||
String getServiceType();
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
*/
|
||||
package sanbing.jcpp.infrastructure.queue.processing;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import lombok.Getter;
|
||||
import sanbing.jcpp.infrastructure.queue.ProtoQueueMsg;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class IdMsgPair<T extends com.google.protobuf.GeneratedMessageV3> {
|
||||
public class IdMsgPair<T extends GeneratedMessage> {
|
||||
@Getter
|
||||
final UUID uuid;
|
||||
@Getter
|
||||
|
||||
Reference in New Issue
Block a user