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";
}
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();
}
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";
}
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";
}
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());
}
Aggregations