Search in sources :

Example 1 with UpstreamClusterChangedEvent

use of com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent in project alibaba-broker-example-parent by linux-china.

the class OpsController method updateUpstream.

@PostMapping("/upstream/update")
public String updateUpstream(@RequestBody String uris) throws Exception {
    UpstreamClusterChangedEvent upstreamClusterChangedEvent = new UpstreamClusterChangedEvent();
    upstreamClusterChangedEvent.setGroup("");
    upstreamClusterChangedEvent.setInterfaceName("*");
    upstreamClusterChangedEvent.setVersion("");
    upstreamClusterChangedEvent.setUris(Arrays.asList(uris.split(",")));
    // passing in the given attributes
    CloudEventImpl<UpstreamClusterChangedEvent> cloudEvent = RSocketCloudEventBuilder.<UpstreamClusterChangedEvent>builder().withType("com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent").withId(UUID.randomUUID().toString()).withTime(OffsetDateTime.now()).withDataContentType(WellKnownMimeType.APPLICATION_JSON.getString()).withSource(new URI("app://" + RSocketAppContext.ID)).withData(upstreamClusterChangedEvent).build();
    eventProcessor.onNext(cloudEvent);
    return "success";
}
Also used : UpstreamClusterChangedEvent(com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent) URI(java.net.URI) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with UpstreamClusterChangedEvent

use of com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent in project alibaba-rsocket-broker by alibaba.

the class RSocketBrokerHandlerRegistryImpl method getBrokerClustersEvent.

private CloudEventImpl<UpstreamClusterChangedEvent> getBrokerClustersEvent(Collection<RSocketBroker> rSocketBrokers, String topology) {
    List<String> uris;
    if ("internet".equals(topology)) {
        uris = rSocketBrokers.stream().filter(rsocketBroker -> rsocketBroker.isActive() && rsocketBroker.getExternalDomain() != null).map(RSocketBroker::getAliasUrl).collect(Collectors.toList());
    } else {
        uris = rSocketBrokers.stream().filter(RSocketBroker::isActive).map(RSocketBroker::getUrl).collect(Collectors.toList());
    }
    UpstreamClusterChangedEvent upstreamClusterChangedEvent = new UpstreamClusterChangedEvent();
    upstreamClusterChangedEvent.setGroup("");
    upstreamClusterChangedEvent.setInterfaceName("*");
    upstreamClusterChangedEvent.setVersion("");
    upstreamClusterChangedEvent.setUris(uris);
    // passing in the given attributes
    return RSocketCloudEventBuilder.builder(upstreamClusterChangedEvent).withDataschema(URI.create("rsocket:event:com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent")).withSource(BrokerAppContext.identity()).build();
}
Also used : Sinks(reactor.core.publisher.Sinks) BearerTokenMetadata(com.alibaba.rsocket.metadata.BearerTokenMetadata) java.util(java.util) ConcurrentHashMap(org.eclipse.collections.impl.map.mutable.ConcurrentHashMap) Multimap(org.eclipse.collections.api.multimap.Multimap) LoggerFactory(org.slf4j.LoggerFactory) BrokerAppContext(com.alibaba.spring.boot.rsocket.broker.BrokerAppContext) RejectedSetupException(io.rsocket.exceptions.RejectedSetupException) RSocketAppPrincipal(com.alibaba.spring.boot.rsocket.broker.security.RSocketAppPrincipal) FastListMultimap(org.eclipse.collections.impl.multimap.list.FastListMultimap) Metrics(io.micrometer.core.instrument.Metrics) ApplicationErrorException(io.rsocket.exceptions.ApplicationErrorException) AuthenticationService(com.alibaba.spring.boot.rsocket.broker.security.AuthenticationService) RSocket(io.rsocket.RSocket) CloudEventImpl(com.alibaba.rsocket.cloudevents.CloudEventImpl) Duration(java.time.Duration) RSocketBroker(com.alibaba.spring.boot.rsocket.broker.cluster.RSocketBroker) Schedulers(reactor.core.scheduler.Schedulers) RSocketFilterChain(com.alibaba.rsocket.route.RSocketFilterChain) URI(java.net.URI) UpstreamClusterChangedEvent(com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent) DoubleFunction(org.eclipse.collections.api.block.function.primitive.DoubleFunction) AppStatusEvent(com.alibaba.rsocket.events.AppStatusEvent) RSocketBrokerManager(com.alibaba.spring.boot.rsocket.broker.cluster.RSocketBrokerManager) ServiceMeshInspector(com.alibaba.spring.boot.rsocket.broker.route.ServiceMeshInspector) RSocketMimeType(com.alibaba.rsocket.metadata.RSocketMimeType) Logger(org.slf4j.Logger) RsocketErrorCode(com.alibaba.rsocket.observability.RsocketErrorCode) Mono(reactor.core.publisher.Mono) ServiceRoutingSelector(com.alibaba.spring.boot.rsocket.broker.route.ServiceRoutingSelector) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) ServiceInstancesChangedEvent(com.alibaba.rsocket.upstream.ServiceInstancesChangedEvent) Nullable(org.jetbrains.annotations.Nullable) Flux(reactor.core.publisher.Flux) AppMetadata(com.alibaba.rsocket.metadata.AppMetadata) MurmurHash3(com.alibaba.rsocket.utils.MurmurHash3) ConnectionSetupPayload(io.rsocket.ConnectionSetupPayload) RSocketCloudEventBuilder(com.alibaba.rsocket.cloudevents.RSocketCloudEventBuilder) LocalReactiveServiceCaller(com.alibaba.rsocket.rpc.LocalReactiveServiceCaller) NotNull(org.jetbrains.annotations.NotNull) ServiceLocator(com.alibaba.rsocket.ServiceLocator) JwtPrincipal(com.alibaba.spring.boot.rsocket.broker.security.JwtPrincipal) RSocketBroker(com.alibaba.spring.boot.rsocket.broker.cluster.RSocketBroker) UpstreamClusterChangedEvent(com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent)

Example 3 with UpstreamClusterChangedEvent

use of com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent in project alibaba-broker-kotlin-example by alibaba-rsocket-broker.

the class OpsController method updateUpstream.

@PostMapping("/upstream/update")
public String updateUpstream(@RequestBody String uris) throws Exception {
    UpstreamClusterChangedEvent upstreamClusterChangedEvent = new UpstreamClusterChangedEvent();
    upstreamClusterChangedEvent.setGroup("");
    upstreamClusterChangedEvent.setInterfaceName("*");
    upstreamClusterChangedEvent.setVersion("");
    upstreamClusterChangedEvent.setUris(Arrays.asList(uris.split(",")));
    // passing in the given attributes
    CloudEventImpl<UpstreamClusterChangedEvent> cloudEvent = RSocketCloudEventBuilder.<UpstreamClusterChangedEvent>builder().withType("com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent").withId(UUID.randomUUID().toString()).withTime(OffsetDateTime.now()).withDataContentType(WellKnownMimeType.APPLICATION_JSON.getString()).withSource(new URI("app://" + RSocketAppContext.ID)).withData(upstreamClusterChangedEvent).build();
    eventProcessor.onNext(cloudEvent);
    return "success";
}
Also used : UpstreamClusterChangedEvent(com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent) URI(java.net.URI) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with UpstreamClusterChangedEvent

use of com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent in project alibaba-rsocket-broker by alibaba.

the class OpsController method updateUpstream.

@PostMapping("/upstream/update")
public String updateUpstream(@RequestBody String uris) throws Exception {
    UpstreamClusterChangedEvent upstreamClusterChangedEvent = new UpstreamClusterChangedEvent();
    upstreamClusterChangedEvent.setGroup("");
    upstreamClusterChangedEvent.setInterfaceName("*");
    upstreamClusterChangedEvent.setVersion("");
    upstreamClusterChangedEvent.setUris(Arrays.asList(uris.split(",")));
    // passing in the given attributes
    final CloudEventImpl<UpstreamClusterChangedEvent> cloudEvent = RSocketCloudEventBuilder.builder(upstreamClusterChangedEvent).build();
    eventProcessor.onNext(cloudEvent);
    return "success";
}
Also used : UpstreamClusterChangedEvent(com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 5 with UpstreamClusterChangedEvent

use of com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent in project alibaba-rsocket-broker by alibaba.

the class CloudEventTest method testCloudEvent.

@Test
public void testCloudEvent() throws Exception {
    UpstreamClusterChangedEvent upstreamClusterChangedEvent = new UpstreamClusterChangedEvent();
    upstreamClusterChangedEvent.setGroup("demo");
    upstreamClusterChangedEvent.setInterfaceName("com.alibaba.user.AccountService");
    upstreamClusterChangedEvent.setVersion("1.0.0");
    upstreamClusterChangedEvent.setUris(Arrays.asList("demo1", "demo2"));
    // passing in the given attributes
    final CloudEventImpl<UpstreamClusterChangedEvent> cloudEvent = RSocketCloudEventBuilder.builder(upstreamClusterChangedEvent).build();
    String text = new String(Json.serialize(cloudEvent));
    CloudEventImpl<UpstreamClusterChangedEvent> event2 = Json.decodeValue(text, UpstreamClusterChangedEvent.class);
    UpstreamClusterChangedEvent upstreamClusterChangedEvent1 = CloudEventSupport.unwrapData(event2, UpstreamClusterChangedEvent.class);
    Assertions.assertEquals(upstreamClusterChangedEvent.getInterfaceName(), upstreamClusterChangedEvent1.getInterfaceName());
}
Also used : UpstreamClusterChangedEvent(com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

UpstreamClusterChangedEvent (com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent)6 URI (java.net.URI)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 ServiceLocator (com.alibaba.rsocket.ServiceLocator)1 CloudEventImpl (com.alibaba.rsocket.cloudevents.CloudEventImpl)1 RSocketCloudEventBuilder (com.alibaba.rsocket.cloudevents.RSocketCloudEventBuilder)1 AppStatusEvent (com.alibaba.rsocket.events.AppStatusEvent)1 AppMetadata (com.alibaba.rsocket.metadata.AppMetadata)1 BearerTokenMetadata (com.alibaba.rsocket.metadata.BearerTokenMetadata)1 RSocketCompositeMetadata (com.alibaba.rsocket.metadata.RSocketCompositeMetadata)1 RSocketMimeType (com.alibaba.rsocket.metadata.RSocketMimeType)1 RsocketErrorCode (com.alibaba.rsocket.observability.RsocketErrorCode)1 RSocketFilterChain (com.alibaba.rsocket.route.RSocketFilterChain)1 LocalReactiveServiceCaller (com.alibaba.rsocket.rpc.LocalReactiveServiceCaller)1 ServiceInstancesChangedEvent (com.alibaba.rsocket.upstream.ServiceInstancesChangedEvent)1 MurmurHash3 (com.alibaba.rsocket.utils.MurmurHash3)1 BrokerAppContext (com.alibaba.spring.boot.rsocket.broker.BrokerAppContext)1 RSocketBroker (com.alibaba.spring.boot.rsocket.broker.cluster.RSocketBroker)1 RSocketBrokerManager (com.alibaba.spring.boot.rsocket.broker.cluster.RSocketBrokerManager)1 ServiceMeshInspector (com.alibaba.spring.boot.rsocket.broker.route.ServiceMeshInspector)1