-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
1,046 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
core/src/main/java/io/cloudevents/core/format/ContentType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2018-Present The CloudEvents Authors | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package io.cloudevents.core.format; | ||
|
||
import io.cloudevents.CloudEvent; | ||
import io.cloudevents.CloudEventData; | ||
import io.cloudevents.rw.CloudEventDataMapper; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
/** | ||
* <p>A construct that aggregates a two-part identifier of file formats and format contents transmitted on the Internet. | ||
* | ||
* <p>The two parts of a {@code ContentType} are its <em>type</em> and a <em>subtype</em>; separated by a forward slash ({@code /}). | ||
* | ||
* <p>The constants enumerated by {@code ContentType} correspond <em>only</em> to the specialized formats supported by the Java™ SDK for CloudEvents. | ||
* | ||
* @see io.cloudevents.core.format.EventFormat | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
public enum ContentType { | ||
|
||
/** | ||
* Content type associated with the JSON event format | ||
*/ | ||
JSON("application/cloudevents+json"), | ||
/** | ||
* The content type for transports sending cloudevents in the protocol buffer format. | ||
*/ | ||
PROTO("application/cloudevents+protobuf"), | ||
/** | ||
* The content type for transports sending cloudevents in XML format. | ||
*/ | ||
XML("application/cloudevents+xml"); | ||
|
||
private String value; | ||
|
||
private ContentType(String value) { this.value = value; } | ||
|
||
/** | ||
* Return a string consisting of the slash-delimited ({@code /}) two-part identifier for this {@code enum} constant. | ||
*/ | ||
public String value() { return value; } | ||
|
||
/** | ||
* Return a string consisting of the slash-delimited ({@code /}) two-part identifier for this {@code enum} constant. | ||
*/ | ||
@Override | ||
public String toString() { return value(); } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# RocketMQ + CloudEvents Sample | ||
|
||
This example demonstrates the integration of [RocketMQ 5.x client library](https://github.com/apache/rocketmq-clients) | ||
with CloudEvents to create a RocketMQ binding. | ||
|
||
## Building the Project | ||
|
||
```shell | ||
mvn package | ||
``` | ||
|
||
## Setting Up a RocketMQ Instance | ||
|
||
Follow the [quickstart guide](https://rocketmq.apache.org/docs/quick-start/01quickstart) on the official RocketMQ | ||
website to set up the necessary components, including nameserver, proxy, and broker. | ||
|
||
## Event Production | ||
|
||
```shell | ||
mvn exec:java -Dexec.mainClass="io.cloudevents.examples.rocketmq.RocketmqProducer" -Dexec.args="foobar:8081 sample-topic" | ||
``` | ||
|
||
## Event Consumption | ||
|
||
```shell | ||
mvn exec:java -Dexec.mainClass="io.cloudevents.examples.rocketmq.RocketmqConsumer" -Dexec.args="foobar:8081 sample-topic sample-consumer-group" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>cloudevents-examples</artifactId> | ||
<groupId>io.cloudevents</groupId> | ||
<version>3.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>cloudevents-rocketmq-example</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.cloudevents</groupId> | ||
<artifactId>cloudevents-rocketmq</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
50 changes: 50 additions & 0 deletions
50
examples/rocketmq/src/main/java/io/cloudevents/examples/rocketmq/RocketmqConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.cloudevents.examples.rocketmq; | ||
|
||
import io.cloudevents.CloudEvent; | ||
import io.cloudevents.core.message.MessageReader; | ||
import io.cloudevents.rocketmq.RocketMqMessageFactory; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import org.apache.rocketmq.client.apis.ClientConfiguration; | ||
import org.apache.rocketmq.client.apis.ClientException; | ||
import org.apache.rocketmq.client.apis.ClientServiceProvider; | ||
import org.apache.rocketmq.client.apis.consumer.ConsumeResult; | ||
import org.apache.rocketmq.client.apis.consumer.FilterExpression; | ||
import org.apache.rocketmq.client.apis.consumer.PushConsumer; | ||
|
||
public class RocketmqConsumer { | ||
private RocketmqConsumer() { | ||
} | ||
|
||
public static void main(String[] args) throws InterruptedException, ClientException, IOException { | ||
if (args.length < 3) { | ||
System.out.println("Usage: rocketmq_consumer <endpoints> <topic> <consumer_group>"); | ||
return; | ||
} | ||
final ClientServiceProvider provider = ClientServiceProvider.loadService(); | ||
String endpoints = args[0]; | ||
ClientConfiguration clientConfiguration = ClientConfiguration.newBuilder() | ||
.setEndpoints(endpoints) | ||
.build(); | ||
FilterExpression filterExpression = new FilterExpression(); | ||
String topic = args[1]; | ||
String consumerGroup = args[2]; | ||
|
||
// Create the RocketMQ Consumer. | ||
PushConsumer pushConsumer = provider.newPushConsumerBuilder() | ||
.setClientConfiguration(clientConfiguration) | ||
.setConsumerGroup(consumerGroup) | ||
.setSubscriptionExpressions(Collections.singletonMap(topic, filterExpression)) | ||
.setMessageListener(messageView -> { | ||
final MessageReader reader = RocketMqMessageFactory.createReader(messageView); | ||
final CloudEvent event = reader.toEvent(); | ||
System.out.println("Received event=" + event + ", messageId=" + messageView.getMessageId()); | ||
return ConsumeResult.SUCCESS; | ||
}) | ||
.build(); | ||
// Block the main thread, no need for production environment. | ||
Thread.sleep(Long.MAX_VALUE); | ||
// Close the push consumer when you don't need it anymore. | ||
pushConsumer.close(); | ||
} | ||
} |
Oops, something went wrong.