You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by GitBox <gi...@apache.org> on 2022/06/17 13:28:10 UTC
[GitHub] [incubator-eventmesh] eight-nines commented on a diff in pull request #914: [ISSUE #865] EM-Webhook: repair exception handling && send webhook CloudEvents
eight-nines commented on code in PR #914:
URL: https://github.com/apache/incubator-eventmesh/pull/914#discussion_r900116406
##########
eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookController.java:
##########
@@ -81,14 +93,44 @@ public void execute(String path, Map<String, String> header, byte[] body) throws
cloudEventId = webHookRequest.getManufacturerEventId();
}
String eventType = manufacturerName + "." + webHookConfig.getManufacturerEventName();
- CloudEvent event = CloudEventBuilder.v1()
- .withId(cloudEventId)
- .withSubject(webHookConfig.getCloudEventName())
- .withSource(URI.create(webHookConfig.getCloudEventSource()))
- .withDataContentType(webHookConfig.getDataContentType())
- .withType(eventType)
- .withData(body)
+
+ // 4. send cloudEvent
+ Properties properties;
+ try (final InputStream inputStream = WebHookController.class.getClassLoader().getResourceAsStream("eventmesh.properties")) {
+ properties = new Properties();
+ properties.load(inputStream);
+ }
+ final String eventMeshIp = properties.getProperty("eventMesh.server.ip");
+ final String eventMeshHttpPort = properties.getProperty("eventMesh.server.http.port");
+
+ String eventMeshIPPort = eventMeshIp + ":" + eventMeshHttpPort;
+
+ // Both the producer and consumer require an instance of EventMeshHttpClientConfig class
+ // that specifies the configuration of EventMesh HTTP client.
+ EventMeshHttpClientConfig eventMeshClientConfig = EventMeshHttpClientConfig.builder()
+ .liteEventMeshAddr(eventMeshIPPort)
+ .producerGroup("eventMesh.webhook.producerGroup")
+ .env(properties.getProperty("eventMesh.server.env"))
+ .idc(properties.getProperty("eventMesh.server.idc"))
+ .ip(properties.getProperty("eventMesh.server.ip"))
+ .sys(properties.getProperty("eventMesh.sysid"))
+ .pid(String.valueOf(ThreadUtils.getPID()))
+ .userName(properties.getProperty("eventMesh.server.http.username"))
+ .password(properties.getProperty("eventMesh.server.http.password"))
.build();
+
+ try (EventMeshHttpProducer eventMeshHttpProducer = new EventMeshHttpProducer(eventMeshClientConfig)) {
+
+ CloudEvent event = CloudEventBuilder.v1()
+ .withId(cloudEventId)
+ .withSubject(webHookConfig.getCloudEventName())
+ .withSource(URI.create(webHookConfig.getCloudEventSource()))
+ .withDataContentType(webHookConfig.getDataContentType())
+ .withType(eventType)
+ .withData(body)
+ .build();
+ eventMeshHttpProducer.publish(event);
Review Comment:
ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org