io.cloudevents.v1.CloudEventImpl Java Examples
The following examples show how to use
io.cloudevents.v1.CloudEventImpl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RSocketBrokerManagerGossipImpl.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
public void onCloudEvent(CloudEventImpl<Object> cloudEvent) { Optional<Object> cloudEventData = cloudEvent.getData(); cloudEventData.ifPresent(data -> { if (data instanceof RSocketFilterEnableEvent) { try { RSocketFilterEnableEvent filterEnableEvent = (RSocketFilterEnableEvent) data; RSocketFilter rsocketFilter = (RSocketFilter) applicationContext.getBean(Class.forName(filterEnableEvent.getFilterClassName())); rsocketFilter.setEnabled(filterEnableEvent.isEnabled()); } catch (Exception ignore) { } } else if (data instanceof AppConfigEvent) { AppConfigEvent appConfigEvent = (AppConfigEvent) data; ConfigurationService configurationService = applicationContext.getBean(ConfigurationService.class); configurationService.put(appConfigEvent.getAppName() + ":" + appConfigEvent.getKey(), appConfigEvent.getVale()).subscribe(); } }); }
Example #2
Source File: RSocketCompositeMetadataTest.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
@Test public void testCloudEvents() throws Exception { final CloudEventImpl<String> cloudEvent = CloudEventBuilder.<String>builder() .withType("eventType") .withId("xxxx") .withTime(ZonedDateTime.now()) .withDataschema(URI.create("demo:demo")) .withDataContentType("text/plain") .withSource(URI.create("app://app1")) .withData("欢迎") .build(); Payload payload = cloudEventToPayload(cloudEvent); payload.getMetadata().rewind(); RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(payload.metadata()); MessageMimeTypeMetadata dataEncodingMetadata = compositeMetadata.getDataEncodingMetadata(); Assertions.assertNotNull(dataEncodingMetadata); System.out.println(dataEncodingMetadata.getMimeType()); }
Example #3
Source File: CloudEventTest.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
@Test public void testJson() throws Exception { // given final String eventId = UUID.randomUUID().toString(); final URI src = URI.create("/trigger"); final String eventType = "My.Cloud.Event.Type"; // passing in the given attributes final CloudEventImpl<String> cloudEvent = CloudEventBuilder.<String>builder() .withType(eventType) .withId(eventId) .withTime(ZonedDateTime.now()) .withDataschema(URI.create("demo:demo")) .withDataContentType("text/plain") .withSource(src) .withData("欢迎") .build(); String text = Json.encode(cloudEvent); System.out.println(text); text = text.replace("欢迎", "leijuan"); Json.decodeValue(text, new TypeReference<CloudEventImpl<String>>() { }); System.out.println(cloudEvent.getData().get()); }
Example #4
Source File: CloudEventTest.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
@Test public void testCloudEvent() throws Exception { UpstreamClusterChangedEvent upstreamClusterChangedEvent = new UpstreamClusterChangedEvent(); upstreamClusterChangedEvent.setGroup("demo"); upstreamClusterChangedEvent.setInterfaceName("com.alibaba.account.AccountService"); upstreamClusterChangedEvent.setVersion("1.0.0"); upstreamClusterChangedEvent.setUris(Arrays.asList("demo1", "demo2")); // passing in the given attributes final CloudEventImpl<UpstreamClusterChangedEvent> cloudEvent = CloudEventBuilder.<UpstreamClusterChangedEvent>builder() .withType("com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent") .withId("xxxxx") .withTime(ZonedDateTime.now()) .withDataschema(URI.create("demo:demo")) .withDataContentType("application/json") .withSource(new URI("demo")) .withData(upstreamClusterChangedEvent) .build(); String text = Json.encode(cloudEvent); CloudEventImpl<UpstreamClusterChangedEvent> event2 = Json.decodeValue(text, new TypeReference<CloudEventImpl<UpstreamClusterChangedEvent>>() { }); UpstreamClusterChangedEvent upstreamClusterChangedEvent1 = CloudEventSupport.unwrapData(event2, UpstreamClusterChangedEvent.class); System.out.println(Json.encode(upstreamClusterChangedEvent1)); Assertions.assertEquals(upstreamClusterChangedEvent.getInterfaceName(), upstreamClusterChangedEvent1.getInterfaceName()); }
Example #5
Source File: RSocketBrokerHandlerRegistryImpl.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
private Flux<Void> broadcastClusterTopology(Collection<RSocketBroker> rSocketBrokers) { final CloudEventImpl<UpstreamClusterChangedEvent> brokerClustersEvent = getBrokerClustersEvent(rSocketBrokers, "intranet"); final CloudEventImpl<UpstreamClusterChangedEvent> brokerClusterAliasesEvent = getBrokerClustersEvent(rSocketBrokers, "internet"); return Flux.fromIterable(findAll()).flatMap(handler -> { Integer roles = handler.getRoles(); String topology = handler.getAppMetadata().getTopology(); Mono<Void> fireEvent; if ("internet".equals(topology)) { // add defaultUri for internet access for IoT devices // RSocketBroker defaultBroker = rsocketBrokerManager.findConsistentBroker(handler.getUuid()); fireEvent = handler.fireCloudEventToPeer(brokerClusterAliasesEvent); } else { fireEvent = handler.fireCloudEventToPeer(brokerClustersEvent); } if (roles == 2) { // publish services only return fireEvent; } else if (roles == 3) { //consume and publish services return fireEvent.delayElement(Duration.ofSeconds(15)); } else { //consume services return fireEvent.delayElement(Duration.ofSeconds(30)); } }); }
Example #6
Source File: DefaultAggregator.java From kogito-runtimes with Apache License 2.0 | 6 votes |
private static CloudEventImpl<TraceEvent> buildNotEnoughDataCloudEvent(DMNModel model, String executionId) { TraceHeader header = new TraceHeader( TraceEventType.DMN, executionId, null, null, null, TraceResourceId.from(model), Stream.of( Message.from(InternalMessageType.NOT_ENOUGH_DATA), model == null ? Message.from(InternalMessageType.DMN_MODEL_NOT_FOUND) : null ).filter(Objects::nonNull).collect(Collectors.toList()) ); TraceEvent event = new TraceEvent(header, Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); return CloudEventBuilder.<TraceEvent>builder() .withType(TraceEvent.class.getName()) .withId(executionId) .withSource(URI.create(URLEncoder.encode(UNKNOWN_SOURCE_URL, StandardCharsets.UTF_8))) .withData(event) .build(); }
Example #7
Source File: AppStatusCloudEventProcessor.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
public void handleAppStatusEvent(CloudEventImpl<?> cloudEvent) { AppStatusEvent appStatusEvent = CloudEventSupport.unwrapData(cloudEvent, AppStatusEvent.class); //安全验证,确保appStatusEvent的ID和cloud source来源的id一致 if (appStatusEvent != null && appStatusEvent.getId().equals(cloudEvent.getAttributes().getSource().getHost())) { RSocketBrokerResponderHandler responderHandler = rsocketBrokerHandlerRegistry.findByUUID(appStatusEvent.getId()); if (responderHandler != null) { AppMetadata appMetadata = responderHandler.getAppMetadata(); if (appStatusEvent.getStatus().equals(AppStatusEvent.STATUS_CONNECTED)) { //app connected registerConfigPush(appMetadata); } else if (appStatusEvent.getStatus().equals(AppStatusEvent.STATUS_SERVING)) { //app serving responderHandler.registerPublishedServices(); } else if (appStatusEvent.getStatus().equals(AppStatusEvent.STATUS_OUT_OF_SERVICE)) { //app out of service responderHandler.unRegisterPublishedServices(); } else if (appStatusEvent.getStatus().equals(AppStatusEvent.STATUS_STOPPED)) { responderHandler.unRegisterPublishedServices(); responderHandler.setAppStatus(AppStatusEvent.STATUS_STOPPED); } } } }
Example #8
Source File: AppStatusCloudEventProcessor.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
private void registerConfigPush(AppMetadata appMetadata) { String appName = appMetadata.getName(); if (!listeners.containsKey(appName)) { listeners.put(appName, configurationService.watch(appName).subscribe(config -> { CloudEventImpl<ConfigEvent> configEvent = CloudEventBuilder.<ConfigEvent>builder() .withId(UUID.randomUUID().toString()) .withTime(ZonedDateTime.now()) .withSource(URI.create("broker://" + RSocketAppContext.ID)) .withType(ConfigEvent.class.getCanonicalName()) .withDataContentType("text/x-java-properties") .withData(new ConfigEvent(appName, "text/x-java-properties", config)) .build(); rsocketBrokerHandlerRegistry.broadcast(appName, configEvent).subscribe(); })); } }
Example #9
Source File: CloudEventSupport.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
@Nullable static <T> T unwrapData(CloudEventImpl<?> cloudEvent, Class<T> targetClass) { return cloudEvent.getData().map(data -> { try { if (data instanceof ObjectNode || data instanceof Map) { return JsonUtils.convertValue(data, targetClass); } else if (data.getClass().isAssignableFrom(targetClass)) { return (T) data; } else if (data instanceof String) { return JsonUtils.readJsonValue((String) data, targetClass); } } catch (Exception ignore) { } return null; }).orElse(null); }
Example #10
Source File: RSocketServicesPublishHook.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
@Override public void onApplicationEvent(@NotNull ApplicationReadyEvent applicationReadyEvent) { UpstreamCluster brokerCluster = upstreamManager.findBroker(); if (brokerCluster == null) return; //rsocket broker cluster logic CloudEventImpl<AppStatusEvent> appStatusEventCloudEvent = CloudEventBuilder.<AppStatusEvent>builder() .withId(UUID.randomUUID().toString()) .withTime(ZonedDateTime.now()) .withSource(URI.create("app://" + RSocketAppContext.ID)) .withType(AppStatusEvent.class.getCanonicalName()) .withDataContentType(WellKnownMimeType.APPLICATION_JSON.getString()) .withData(new AppStatusEvent(RSocketAppContext.ID, AppStatusEvent.STATUS_SERVING)) .build(); LoadBalancedRSocket loadBalancedRSocket = brokerCluster.getLoadBalancedRSocket(); String brokers = String.join(",", loadBalancedRSocket.getActiveSockets().keySet()); loadBalancedRSocket.fireCloudEventToUpstreamAll(appStatusEventCloudEvent) .doOnSuccess(aVoid -> log.info(RsocketErrorCode.message("RST-301200", brokers))) .subscribe(); CloudEventImpl<ServicesExposedEvent> servicesExposedEventCloudEvent = rsocketRequesterSupport.servicesExposedEvent().get(); if (servicesExposedEventCloudEvent != null) { loadBalancedRSocket.fireCloudEventToUpstreamAll(servicesExposedEventCloudEvent).doOnSuccess(aVoid -> { String exposedServices = rsocketRequesterSupport.exposedServices().get().stream().map(ServiceLocator::getGsv).collect(Collectors.joining(",")); log.info(RsocketErrorCode.message("RST-301201", exposedServices, brokers)); }).subscribe(); } }
Example #11
Source File: RSocketResponderHandler.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
public RSocketResponderHandler(LocalReactiveServiceCaller serviceCall, TopicProcessor<CloudEventImpl> eventProcessor, RSocket requester, ConnectionSetupPayload setupPayload) { this.localServiceCaller = serviceCall; this.eventProcessor = eventProcessor; this.requester = requester; this.comboOnClose = Mono.first(super.onClose(), requester.onClose()); //parse composite metadata RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(setupPayload.metadata()); if (compositeMetadata.contains(RSocketMimeType.Application)) { AppMetadata appMetadata = AppMetadata.from(compositeMetadata.getMetadata(RSocketMimeType.Application)); //from remote requester if (!appMetadata.getUuid().equals(RSocketAppContext.ID)) { RSocketMimeType dataType = RSocketMimeType.valueOfType(setupPayload.dataMimeType()); if (dataType != null) { this.defaultMessageMimeType = new MessageMimeTypeMetadata(dataType); } } } try { Class.forName("brave.propagation.TraceContext"); } catch (ClassNotFoundException e) { this.braveTracing = false; } }
Example #12
Source File: RSocketBrokerManagerGossipImplTest.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
@Test public void testGossipMessageWithCloudEvents() throws Exception { AppStatusEvent appStatusEvent = new AppStatusEvent("1", 1); CloudEventImpl<AppStatusEvent> cloudEvent = CloudEventBuilder.<AppStatusEvent>builder() .withId("1") .withSource(URI.create("app://1")) .withType("type1") .withTime(ZonedDateTime.now()) .withDataContentType("application/json") .withData(appStatusEvent) .withSubject("app status update") .build(); Message message = Message.builder().correlationId("1").data(cloudEvent).build(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); messageCodec.serialize(message, bos); Message message1 = messageCodec.deserialize(new ByteArrayInputStream(bos.toByteArray())); CloudEventImpl<AppStatusEvent> cloudEvent2 = message1.data(); Assertions.assertThat(cloudEvent2.getData()).isPresent(); }
Example #13
Source File: OpsController.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
@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 = CloudEventBuilder.<UpstreamClusterChangedEvent>builder() .withType("com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent") .withId(UUID.randomUUID().toString()) .withTime(ZonedDateTime.now()) .withDataschema(URI.create("rsocket:event")) .withDataContentType("application/json") .withSource(new URI("app://" + RSocketAppContext.ID)) .withData(upstreamClusterChangedEvent) .build(); eventProcessor.onNext(cloudEvent); return "success"; }
Example #14
Source File: UpstreamForwardRSocket.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
@Override public @NotNull Mono<Void> metadataPush(@NotNull Payload payload) { try { if (payload.metadata().readableBytes() > 0) { CloudEventImpl<?> cloudEvent = Json.decodeValue(payload.getMetadataUtf8(), CLOUD_EVENT_TYPE_REFERENCE); //todo String type = cloudEvent.getAttributes().getType(); if (UpstreamClusterChangedEvent.class.getCanonicalName().equalsIgnoreCase(type)) { handleUpstreamClusterChangedEvent(cloudEvent); } } } catch (Exception e) { log.error(RsocketErrorCode.message(RsocketErrorCode.message("RST-610500", e.getMessage())), e); } finally { ReferenceCountUtil.safeRelease(payload); } return Mono.empty(); }
Example #15
Source File: ConfigurationEventProcessor.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
public void handleConfigurationEvent(CloudEventImpl<?> cloudEvent) { // replyto support // cloudEvent.getExtensions().get("replyto"); rsocket:///REQUEST_FNF/com.xxxx.XxxService#method ConfigEvent configEvent = CloudEventSupport.unwrapData(cloudEvent, ConfigEvent.class); // validate config content if (configEvent!=null && applicationName.equalsIgnoreCase(configEvent.getAppName()) && !RSocketConfigPropertySourceLocator.getLastConfigText().equals(configEvent.getContent())) { Properties configProperties = RSocketConfigPropertySourceLocator.CONFIG_PROPERTIES.get(applicationName); if (configProperties != null) { try { configProperties.load(new StringReader(configEvent.getContent())); log.info(RsocketErrorCode.message("RST-202200", applicationName)); contextRefresher.refresh(); RSocketConfigPropertySourceLocator.setLastConfigText(configEvent.getContent()); log.info(RsocketErrorCode.message("RST-202001")); } catch (Exception e) { log.info(RsocketErrorCode.message("RST-202501"), e); } } } }
Example #16
Source File: DefaultAggregatorTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test void test_Aggregate_EvaluateDecisionService_NullModel_DmnModelNotFound() { final DefaultAggregator aggregator = new DefaultAggregator(); List<EvaluateEvent> events = DecisionTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_DECISION_SERVICE_JSON_RESOURCE); CloudEventImpl<TraceEvent> cloudEvent = aggregator.aggregate(null, EVALUATE_DECISION_SERVICE_EXECUTION_ID, events); TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_DECISION_SERVICE_EXECUTION_ID); assertTraceEvent(traceEvent, 1, 1, 1); assertTraceEventInternalMessage(traceEvent, InternalMessageType.DMN_MODEL_NOT_FOUND); }
Example #17
Source File: LoadBalancedRSocket.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
@Override public Mono<Void> fireCloudEvent(CloudEventImpl<?> cloudEvent) { try { Payload payload = cloudEventToMetadataPushPayload(cloudEvent); return metadataPush(payload); } catch (Exception e) { return Mono.error(e); } }
Example #18
Source File: DefaultAggregatorTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test void test_Aggregate_EvaluateAll_ListWithOnlyFirstEvent_NoExecutionSteps() { final DefaultAggregator aggregator = new DefaultAggregator(); final List<EvaluateEvent> events = DecisionTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_ALL_JSON_RESOURCE).stream() .limit(1).collect(Collectors.toList()); CloudEventImpl<TraceEvent> cloudEvent = aggregator.aggregate(model, EVALUATE_ALL_EXECUTION_ID, events); TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_ALL_EXECUTION_ID); assertTraceEvent(traceEvent, 2, 2, 0); }
Example #19
Source File: DefaultAggregatorTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test void test_Aggregate_EvaluateDecisionService_ListWithMissingBeforeEvaluateDecisionEvent_NoExecutionStepHierarchy() { final DefaultAggregator aggregator = new DefaultAggregator(); final List<EvaluateEvent> events = DecisionTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_DECISION_SERVICE_JSON_RESOURCE).stream() .filter(e -> !(e.getType() == EvaluateEventType.BEFORE_EVALUATE_DECISION && DECISION_SERVICE_DECISION_ID.equals(e.getNodeId()))) .collect(Collectors.toList()); CloudEventImpl<TraceEvent> cloudEvent = aggregator.aggregate(model, EVALUATE_DECISION_SERVICE_EXECUTION_ID, events); TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_DECISION_SERVICE_EXECUTION_ID); assertTraceEventWithNoExecutionStepsHierarchy(traceEvent, 1, 1, 3); }
Example #20
Source File: DefaultAggregatorTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test void test_Aggregate_EvaluateDecisionService_ListWithOnlyFirstEvent_NoExecutionSteps() { final DefaultAggregator aggregator = new DefaultAggregator(); final List<EvaluateEvent> events = DecisionTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_DECISION_SERVICE_JSON_RESOURCE).stream() .limit(1).collect(Collectors.toList()); CloudEventImpl<TraceEvent> cloudEvent = aggregator.aggregate(model, EVALUATE_DECISION_SERVICE_EXECUTION_ID, events); TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_DECISION_SERVICE_EXECUTION_ID); assertTraceEvent(traceEvent, 1, 0, 0); }
Example #21
Source File: DefaultAggregatorTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test void test_Aggregate_EvaluateAll_ListWithMissingLastAfterEvaluateDecisionEvent_NoExecutionStepHierarchy() { final DefaultAggregator aggregator = new DefaultAggregator(); final List<EvaluateEvent> events = DecisionTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_ALL_JSON_RESOURCE).stream() .filter(e -> !(e.getType() == EvaluateEventType.AFTER_EVALUATE_DECISION && LAST_DECISION_NODE_ID.equals(e.getNodeId()))) .collect(Collectors.toList()); CloudEventImpl<TraceEvent> cloudEvent = aggregator.aggregate(model, EVALUATE_ALL_EXECUTION_ID, events); TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_ALL_EXECUTION_ID); assertTraceEventWithNoExecutionStepsHierarchy(traceEvent, 2, 2, 5); }
Example #22
Source File: DefaultAggregatorTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test void test_Aggregate_EvaluateAll_ListWithMissingFirstAfterEvaluateDecisionEvent_NoExecutionStepHierarchy() { final DefaultAggregator aggregator = new DefaultAggregator(); final List<EvaluateEvent> events = DecisionTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_ALL_JSON_RESOURCE).stream() .filter(e -> !(e.getType() == EvaluateEventType.AFTER_EVALUATE_DECISION && FIRST_DECISION_NODE_ID.equals(e.getNodeId()))) .collect(Collectors.toList()); CloudEventImpl<TraceEvent> cloudEvent = aggregator.aggregate(model, EVALUATE_ALL_EXECUTION_ID, events); TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_ALL_EXECUTION_ID); assertTraceEventWithNoExecutionStepsHierarchy(traceEvent, 2, 2, 5); }
Example #23
Source File: DefaultAggregatorTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test void test_Aggregate_EvaluateAll_ListWithMissingFirstBeforeEvaluateDecisionEvent_NoExecutionStepHierarchy() { final DefaultAggregator aggregator = new DefaultAggregator(); final List<EvaluateEvent> events = DecisionTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_ALL_JSON_RESOURCE).stream() .filter(e -> !(e.getType() == EvaluateEventType.BEFORE_EVALUATE_DECISION && FIRST_DECISION_NODE_ID.equals(e.getNodeId()))) .collect(Collectors.toList()); CloudEventImpl<TraceEvent> cloudEvent = aggregator.aggregate(model, EVALUATE_ALL_EXECUTION_ID, events); TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_ALL_EXECUTION_ID); assertTraceEventWithNoExecutionStepsHierarchy(traceEvent, 2, 2, 6); }
Example #24
Source File: DefaultAggregatorTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test void test_Aggregate_EvaluateDecisionService_ValidList_Working() { final DefaultAggregator aggregator = new DefaultAggregator(); List<EvaluateEvent> events = DecisionTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_DECISION_SERVICE_JSON_RESOURCE); CloudEventImpl<TraceEvent> cloudEvent = aggregator.aggregate(model, EVALUATE_DECISION_SERVICE_EXECUTION_ID, events); TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_DECISION_SERVICE_EXECUTION_ID); assertTraceEvent(traceEvent, 1, 1, 1); }
Example #25
Source File: CloudEventTest.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
@Test public void testConvert() throws Exception { ConfigEvent configurationEvent = new ConfigEvent("app1", "text/plain", "Hello"); CloudEventImpl<ConfigEvent> cloudEvent = configurationEvent.toCloudEvent(URI.create("demo")); String jsonText = Json.encode(cloudEvent); System.out.println(jsonText); CloudEventImpl<ConfigEvent> configurationEvent2 = Json.decodeValue(jsonText, new TypeReference<CloudEventImpl<ConfigEvent>>() { }); System.out.println(Json.encode(configurationEvent2)); }
Example #26
Source File: CloudEventSupport.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
default CloudEventImpl<T> toCloudEvent(URI source) { CloudEventBuilder<T> builder = CloudEventBuilder.builder(); builder.withId(UUID.randomUUID().toString()); builder.withType(this.getClass().getCanonicalName()); builder.withDataContentType(RSocketMimeType.CloudEventsJson.getType()); builder.withSource(source); builder.withTime(ZonedDateTime.now()); builder.withData((T) this); return builder.build(); }
Example #27
Source File: RSocketResponderHandler.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
/** * fire cloud event to peer * * @param cloudEvent cloud event * @return void */ public Mono<Void> fireCloudEventToPeer(CloudEventImpl<?> cloudEvent) { try { Payload payload = cloudEventToMetadataPushPayload(cloudEvent); return requester.metadataPush(payload); } catch (Exception e) { return Mono.error(e); } }
Example #28
Source File: CloudEventRSocket.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
default Payload cloudEventToMetadataPushPayload(CloudEventImpl<?> cloudEvent) { ByteBuf byteBuf = PooledByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream bos = new ByteBufOutputStream(byteBuf); JsonUtils.objectMapper.writeValue((OutputStream) bos, cloudEvent); return ByteBufPayload.create(Unpooled.EMPTY_BUFFER, byteBuf); } catch (Exception e) { ReferenceCountUtil.safeRelease(byteBuf); throw new EncodingException(RsocketErrorCode.message("RST-700500", "CloudEventImpl", "ByteBuf"), e); } }
Example #29
Source File: LoadBalancedRSocket.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
public void onRSocketReconnected(String rsocketUri, RSocket rsocket) { this.activeSockets.put(rsocketUri, rsocket); this.unHealthyUriSet.remove(rsocketUri); this.randomSelector = new RandomSelector<>(this.serviceId, new ArrayList<>(activeSockets.values())); rsocket.onClose().subscribe(aVoid -> onRSocketClosed(rsocketUri, rsocket, null)); CloudEventImpl<ServicesExposedEvent> cloudEvent = requesterSupport.servicesExposedEvent().get(); if (cloudEvent != null) { try { Payload payload = cloudEventToMetadataPushPayload(cloudEvent); rsocket.metadataPush(payload).subscribe(); } catch (Exception ignore) { } } }
Example #30
Source File: LoadBalancedRSocket.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
/** * fire cloud event to upstream active rsockets * * @param cloudEvent cloud event * @return void */ public Mono<Void> fireCloudEventToUpstreamAll(CloudEventImpl<?> cloudEvent) { try { return Flux.fromIterable(this.getActiveSockets().values()) .flatMap(rsocket -> rsocket.metadataPush(cloudEventToMetadataPushPayload(cloudEvent))) .doOnError(throwable -> log.error(RsocketErrorCode.message("RST-610502"), throwable)) .then(); } catch (Exception e) { return Mono.error(e); } }