use of com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler in project alibaba-rsocket-broker by alibaba.
the class DiscoveryServiceImpl method findServiceInstances.
@NotNull
private Flux<RSocketServiceInstance> findServiceInstances(String serviceId) {
Integer serviceHashCode = ServiceLocator.serviceHashCode(serviceId);
Collection<Integer> instanceIdList = routingSelector.findHandlers(serviceHashCode);
if (instanceIdList.isEmpty()) {
return findServiceInstancesByAppName(serviceId);
}
List<RSocketServiceInstance> serviceInstances = new ArrayList<>();
for (Integer handlerId : instanceIdList) {
RSocketBrokerResponderHandler handler = handlerRegistry.findById(handlerId);
if (handler != null) {
serviceInstances.add(constructServiceInstance(handler));
}
}
return Flux.fromIterable(serviceInstances);
}
use of com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler in project alibaba-rsocket-broker by alibaba.
the class UpstreamForwardRSocket method findDestination.
private Mono<RSocket> findDestination(GSVRoutingMetadata routingMetaData) {
return Mono.create(sink -> {
String gsv = routingMetaData.gsv();
Integer serviceId = routingMetaData.id();
RSocketBrokerResponderHandler targetHandler = null;
RSocket rsocket = null;
Exception error = null;
String endpoint = routingMetaData.getEndpoint();
if (endpoint != null && !endpoint.isEmpty()) {
targetHandler = findDestinationWithEndpoint(endpoint, serviceId);
if (targetHandler == null) {
error = new InvalidException(RsocketErrorCode.message("RST-900405", gsv, endpoint));
}
} else {
Integer targetHandlerId = routingSelector.findHandler(serviceId);
if (targetHandlerId != null) {
targetHandler = handlerRegistry.findById(targetHandlerId);
} else {
error = new InvalidException(RsocketErrorCode.message("RST-900404", gsv));
}
}
// security check
if (targetHandler != null) {
rsocket = targetHandler.getPeerRsocket();
/* if (serviceMeshInspector.isRequestAllowed(this.principal, gsv, targetHandler.principal)) {
rsocket = targetHandler.getPeerRsocket();
} else {
error = new ApplicationErrorException(RsocketErrorCode.message("RST-900401", gsv));
}*/
}
if (rsocket != null) {
sink.success(rsocket);
} else if (error != null) {
sink.error(error);
} else {
sink.error(new ApplicationErrorException(RsocketErrorCode.message("RST-900404", gsv)));
}
});
}
use of com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler in project alibaba-rsocket-broker by alibaba.
the class AppQueryController method query.
@GetMapping("/{appName}")
public Flux<Map<String, Object>> query(@PathVariable(name = "appName") String appName) {
List<Map<String, Object>> apps = new ArrayList<>();
Collection<RSocketBrokerResponderHandler> handlers = handlerRegistry.findByAppName(appName);
if (handlers != null) {
for (RSocketBrokerResponderHandler handler : handlers) {
Map<String, Object> app = new HashMap<>();
AppMetadata appMetadata = handler.getAppMetadata();
app.put("ip", appMetadata.getIp());
app.put("uuid", appMetadata.getUuid());
app.put("startedAt", appMetadata.getConnectedAt());
apps.add(app);
}
}
return Flux.fromIterable(apps);
}
use of com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler in project alibaba-rsocket-broker by alibaba.
the class ServiceTestingView method callRSocketService.
public void callRSocketService(String service, String method, @Nullable String jsonData, Pre response) {
Integer handlerId = this.routingSelector.findHandler(ServiceLocator.serviceHashCode(service));
if (handlerId != null) {
RSocketBrokerResponderHandler handler = handlerRegistry.findById(handlerId);
if (handler != null) {
// composite metadata for health check
RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(new GSVRoutingMetadata(null, service, method, null), new MessageMimeTypeMetadata(RSocketMimeType.Json));
ByteBuf payLoadData;
if (jsonData == null || jsonData.isEmpty()) {
payLoadData = Unpooled.EMPTY_BUFFER;
} else {
payLoadData = Unpooled.wrappedBuffer(jsonData.getBytes(StandardCharsets.UTF_8));
}
Payload requestPayload = ByteBufPayload.create(payLoadData, compositeMetadata.getContent());
handler.getPeerRsocket().requestResponse(requestPayload).doOnError(throwable -> getUI().ifPresent(ui -> ui.access(() -> {
response.setText(throwable.getMessage());
}))).subscribe(payload -> getUI().ifPresent(ui -> ui.access(() -> {
response.setText(payload.getDataUtf8());
})));
} else {
this.serviceNameFiled.setInvalid(true);
this.serviceNameFiled.setErrorMessage("No Service Provider!");
}
} else {
this.serviceNameFiled.setInvalid(true);
this.serviceNameFiled.setErrorMessage("Service not found!");
}
}
use of com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler in project alibaba-rsocket-broker by alibaba.
the class ServiceQueryController method queryDefinition.
@GetMapping(value = "/definition/{serviceName}")
public Mono<String> queryDefinition(@PathVariable(name = "serviceName") String serviceName) {
Integer handler = routingSelector.findHandler(new ServiceLocator("", serviceName, "").getId());
if (handler != null) {
RSocketBrokerResponderHandler brokerResponderHandler = brokerHandlerRegistry.findById(handler);
if (brokerResponderHandler != null) {
GSVRoutingMetadata routingMetadata = new GSVRoutingMetadata("", ReactiveServiceDiscovery.class.getCanonicalName() + ".findServiceByFullName", "");
RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(routingMetadata, jsonMetaEncoding);
ByteBuf bodyBuf = Unpooled.wrappedBuffer(("[\"" + serviceName + "\"]").getBytes(StandardCharsets.UTF_8));
return brokerResponderHandler.getPeerRsocket().requestResponse(ByteBufPayload.create(bodyBuf, compositeMetadata.getContent())).map(Payload::getDataUtf8);
}
}
return Mono.error(new Exception(RsocketErrorCode.message("RST-900404", serviceName)));
}
Aggregations