use of io.smallrye.reactive.messaging.ce.IncomingCloudEventMetadata in project smallrye-reactive-messaging by smallrye.
the class CloudEventConsumptionTest method testReceivingStructuredCloudEventsNoData.
@Test
public void testReceivingStructuredCloudEventsNoData() {
String address = UUID.randomUUID().toString();
new MapBasedConfig().with("mp.messaging.incoming.source.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.incoming.source.address", address).with("mp.messaging.incoming.source.host", host).with("mp.messaging.incoming.source.port", port).with("mp.messaging.incoming.source.tracing-enabled", false).with("amqp-username", username).with("amqp-password", password).write();
weld.addBeanClass(MyConsumptionBean.class);
container = weld.initialize();
await().until(() -> isAmqpConnectorReady(container));
MyConsumptionBean bean = container.getBeanManager().createInstance().select(MyConsumptionBean.class).get();
usage.produce(address, 1, () -> {
JsonObject json = new JsonObject().put("specversion", CloudEventMetadata.CE_VERSION_1_0).put("type", "type").put("id", "id").put("source", "test://test").put("subject", "foo").put("datacontenttype", "application/json").put("dataschema", "http://schema.io").put("time", "2020-07-23T09:12:34Z");
return AmqpMessage.create().withJsonObjectAsBody(json).contentType(AmqpCloudEventHelper.STRUCTURED_CONTENT_TYPE).build();
});
await().atMost(2, TimeUnit.MINUTES).until(() -> bean.getList().size() >= 1);
Message<JsonObject> message = bean.getList().get(0);
IncomingCloudEventMetadata<JsonObject> metadata = message.getMetadata(IncomingCloudEventMetadata.class).orElse(null);
assertThat(metadata).isNotNull();
assertThat(metadata.getSpecVersion()).isEqualTo(CloudEventMetadata.CE_VERSION_1_0);
assertThat(metadata.getType()).isEqualTo("type");
assertThat(metadata.getId()).isEqualTo("id");
assertThat(metadata.getSource()).isEqualTo(URI.create("test://test"));
assertThat(metadata.getData()).isNull();
assertThat(message.getPayload()).isNull();
}
use of io.smallrye.reactive.messaging.ce.IncomingCloudEventMetadata in project smallrye-reactive-messaging by smallrye.
the class CloudEventConsumptionTest method testReceivingBinaryCloudEventsWithSupportDisabled.
@Test
public void testReceivingBinaryCloudEventsWithSupportDisabled() {
String address = UUID.randomUUID().toString();
new MapBasedConfig().with("mp.messaging.incoming.source.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.incoming.source.address", address).with("mp.messaging.incoming.source.host", host).with("mp.messaging.incoming.source.port", port).with("mp.messaging.incoming.source.cloud-events", false).with("mp.messaging.incoming.source.tracing-enabled", false).with("amqp-username", username).with("amqp-password", password).write();
weld.addBeanClass(MyConsumptionBean.class);
container = weld.initialize();
await().until(() -> isAmqpConnectorReady(container));
MyConsumptionBean bean = container.getBeanManager().createInstance().select(MyConsumptionBean.class).get();
usage.produce(address, 1, () -> {
JsonObject json = new JsonObject().put(AmqpCloudEventHelper.AMQP_HEADER_FOR_SPEC_VERSION, CloudEventMetadata.CE_VERSION_1_0).put(AmqpCloudEventHelper.AMQP_HEADER_FOR_TYPE, "type").put(AmqpCloudEventHelper.AMQP_HEADER_FOR_ID, "id").put(AmqpCloudEventHelper.AMQP_HEADER_FOR_SOURCE, "test://test").put(AmqpCloudEventHelper.AMQP_HEADER_FOR_SUBJECT, "foo").put(AmqpCloudEventHelper.AMQP_HEADER_FOR_SCHEMA, "http://schema.io").put(AmqpCloudEventHelper.AMQP_HEADER_FOR_TIME, "2020-07-23T09:12:34Z");
JsonObject payload = new JsonObject();
payload.put("name", "neo");
return AmqpMessage.create().applicationProperties(json).withJsonObjectAsBody(payload).build();
});
await().atMost(2, TimeUnit.MINUTES).until(() -> bean.getList().size() >= 1);
Message<JsonObject> message = bean.getList().get(0);
IncomingCloudEventMetadata<JsonObject> metadata = message.getMetadata(IncomingCloudEventMetadata.class).orElse(null);
IncomingAmqpMetadata amqpMetadata = message.getMetadata(IncomingAmqpMetadata.class).orElse(null);
assertThat(metadata).isNull();
assertThat(amqpMetadata).isNotNull();
assertThat(message.getPayload()).isInstanceOf(JsonObject.class).containsExactly(entry("name", "neo"));
assertThat(amqpMetadata.getProperties().getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_TYPE)).isEqualTo("type");
}
use of io.smallrye.reactive.messaging.ce.IncomingCloudEventMetadata in project smallrye-reactive-messaging by smallrye.
the class CloudEventConsumptionTest method testReceivingStructuredCloudEventsWithJsonObjectPayload.
@Test
public void testReceivingStructuredCloudEventsWithJsonObjectPayload() {
String address = UUID.randomUUID().toString();
new MapBasedConfig().with("mp.messaging.incoming.source.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.incoming.source.address", address).with("mp.messaging.incoming.source.host", host).with("mp.messaging.incoming.source.port", port).with("mp.messaging.incoming.source.tracing-enabled", false).with("amqp-username", username).with("amqp-password", password).write();
weld.addBeanClass(MyConsumptionBean.class);
container = weld.initialize();
await().until(() -> isAmqpConnectorReady(container));
MyConsumptionBean bean = container.getBeanManager().createInstance().select(MyConsumptionBean.class).get();
usage.produce(address, 1, () -> {
JsonObject json = new JsonObject().put("specversion", CloudEventMetadata.CE_VERSION_1_0).put("type", "type").put("id", "id").put("source", "test://test").put("subject", "foo").put("datacontenttype", "application/json").put("dataschema", "http://schema.io").put("time", "2020-07-23T09:12:34Z").put("data", new JsonObject().put("name", "neo"));
return AmqpMessage.create().withJsonObjectAsBody(json).contentType(AmqpCloudEventHelper.STRUCTURED_CONTENT_TYPE).build();
});
await().atMost(2, TimeUnit.MINUTES).until(() -> bean.getList().size() >= 1);
Message<JsonObject> message = bean.getList().get(0);
IncomingCloudEventMetadata<JsonObject> metadata = message.getMetadata(IncomingCloudEventMetadata.class).orElse(null);
assertThat(metadata).isNotNull();
assertThat(metadata.getSpecVersion()).isEqualTo(CloudEventMetadata.CE_VERSION_1_0);
assertThat(metadata.getType()).isEqualTo("type");
assertThat(metadata.getId()).isEqualTo("id");
assertThat(metadata.getSource()).isEqualTo(URI.create("test://test"));
assertThat(metadata.getSubject()).hasValue("foo");
assertThat(metadata.getDataContentType()).hasValue("application/json");
assertThat(metadata.getDataSchema()).hasValue(URI.create("http://schema.io"));
assertThat(metadata.getTimeStamp()).isNotEmpty();
assertThat(metadata.getData().getString("name")).isEqualTo("neo");
assertThat(message.getPayload()).isInstanceOf(JsonObject.class);
assertThat(message.getPayload().getString("name")).isEqualTo("neo");
}
use of io.smallrye.reactive.messaging.ce.IncomingCloudEventMetadata in project smallrye-reactive-messaging by smallrye.
the class CloudEventConsumptionTest method testReceivingStructuredCloudEventsWithSupportDisabled.
@Test
public void testReceivingStructuredCloudEventsWithSupportDisabled() {
String address = UUID.randomUUID().toString();
new MapBasedConfig().with("mp.messaging.incoming.source.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.incoming.source.address", address).with("mp.messaging.incoming.source.host", host).with("mp.messaging.incoming.source.port", port).with("mp.messaging.incoming.source.tracing-enabled", false).with("mp.messaging.incoming.source.cloud-events", false).with("amqp-username", username).with("amqp-password", password).write();
weld.addBeanClass(MyConsumptionBean.class);
container = weld.initialize();
await().until(() -> isAmqpConnectorReady(container));
MyConsumptionBean bean = container.getBeanManager().createInstance().select(MyConsumptionBean.class).get();
usage.produce(address, 1, () -> {
JsonObject json = new JsonObject().put("specversion", CloudEventMetadata.CE_VERSION_1_0).put("type", "type").put("id", "id").put("source", "test://test").put("subject", "foo").put("datacontenttype", "application/json").put("dataschema", "http://schema.io").put("time", "2020-07-23T09:12:34Z").put("data", new JsonObject().put("name", "neo"));
return AmqpMessage.create().withJsonObjectAsBody(json).contentType(AmqpCloudEventHelper.STRUCTURED_CONTENT_TYPE).build();
});
await().atMost(2, TimeUnit.MINUTES).until(() -> bean.getList().size() >= 1);
Message<JsonObject> message = bean.getList().get(0);
IncomingCloudEventMetadata<JsonObject> metadata = message.getMetadata(IncomingCloudEventMetadata.class).orElse(null);
IncomingAmqpMetadata amqpMetadata = message.getMetadata(IncomingAmqpMetadata.class).orElse(null);
assertThat(metadata).isNull();
assertThat(amqpMetadata).isNotNull();
}
use of io.smallrye.reactive.messaging.ce.IncomingCloudEventMetadata in project smallrye-reactive-messaging by smallrye.
the class CloudEventConsumptionTest method testReceivingBinaryCloudEventsUsingJsonPayload.
@SuppressWarnings("unchecked")
@Test
public void testReceivingBinaryCloudEventsUsingJsonPayload() {
String address = UUID.randomUUID().toString();
new MapBasedConfig().with("mp.messaging.incoming.source.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.incoming.source.address", address).with("mp.messaging.incoming.source.host", host).with("mp.messaging.incoming.source.port", port).with("mp.messaging.incoming.source.tracing-enabled", false).with("amqp-username", username).with("amqp-password", password).write();
weld.addBeanClass(MyConsumptionBean.class);
container = weld.initialize();
await().until(() -> isAmqpConnectorReady(container));
MyConsumptionBean bean = container.getBeanManager().createInstance().select(MyConsumptionBean.class).get();
usage.produce(address, 1, () -> {
JsonObject json = new JsonObject().put(AmqpCloudEventHelper.AMQP_HEADER_FOR_SPEC_VERSION, CloudEventMetadata.CE_VERSION_1_0).put(AmqpCloudEventHelper.AMQP_HEADER_FOR_TYPE, "type").put(AmqpCloudEventHelper.AMQP_HEADER_FOR_ID, "id").put(AmqpCloudEventHelper.AMQP_HEADER_FOR_SOURCE, "test://test").put(AmqpCloudEventHelper.AMQP_HEADER_FOR_SUBJECT, "foo").put(AmqpCloudEventHelper.AMQP_HEADER_FOR_SCHEMA, "http://schema.io").put(AmqpCloudEventHelper.AMQP_HEADER_FOR_TIME, "2020-07-23T09:12:34Z");
JsonObject payload = new JsonObject();
payload.put("name", "neo");
return AmqpMessage.create().applicationProperties(json).withJsonObjectAsBody(payload).build();
});
await().atMost(2, TimeUnit.MINUTES).until(() -> bean.getList().size() >= 1);
Message<JsonObject> message = bean.getList().get(0);
IncomingCloudEventMetadata<JsonObject> metadata = message.getMetadata(IncomingCloudEventMetadata.class).orElse(null);
assertThat(metadata).isNotNull();
assertThat(metadata.getSpecVersion()).isEqualTo(CloudEventMetadata.CE_VERSION_1_0);
assertThat(metadata.getType()).isEqualTo("type");
assertThat(metadata.getId()).isEqualTo("id");
assertThat(metadata.getSource()).isEqualTo(URI.create("test://test"));
assertThat(metadata.getSubject()).hasValue("foo");
assertThat(metadata.getDataContentType()).hasValue("application/json");
assertThat(metadata.getDataSchema()).hasValue(URI.create("http://schema.io"));
assertThat(metadata.getTimeStamp()).isNotEmpty();
assertThat(metadata.getData().getString("name")).isEqualTo("neo");
assertThat(message.getPayload()).isInstanceOf(JsonObject.class);
assertThat(message.getPayload().getString("name")).isEqualTo("neo");
}
Aggregations