Skip to content

Commit b536721

Browse files
vesensevongosling
authored andcommittedJun 11, 2018
ROCKETMQ-157: Serializer & Deserializer support for RocketMQ (apache#42)
* Serializer&Deserializer support for RocketMQ
1 parent 554ced8 commit b536721

File tree

36 files changed

+2553
-0
lines changed

36 files changed

+2553
-0
lines changed
 

‎rocketmq-serializer/README.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# RocketMQ-Serializer
2+
RocketMQ-Serializer is a RocketMQ extend library for serializing and deserializing message body.
3+
Both APIs and implements(string, json, avro...) are included in this module.
4+
5+
## APIs
6+
The core serializer & deserializer API are interfaces `RocketMQSerializer` and `RocketMQDeserializer`.
7+
In order to centralized manage avro schemas, you can implement `SchemaRegistry` interface in `rocketmq-serializer-avro` module,
8+
and use `SchemaRegistry` registering and getting schemas.
9+
10+
## Implementations
11+
### Supported Formats
12+
13+
| Format | Serializer | Deserializer |
14+
| ------------- |:-------------:|:------:|
15+
| Raw String | Y | Y |
16+
| JSON | Y | Y |
17+
| Avro Generic | Y | Y |
18+
| Avro Specified | Y | Y |
19+
20+
Some serializer performance research please refer to https://github.com/vongosling/jvm-serializer.
21+
22+
### User Defined Formats
23+
You can define your format just implements `RocketMQSerializer` and `RocketMQDeserializer`.
24+
25+
## Tools
26+
`Messages` provides methods like `newMessage` and `getMessageBody` to map between user class and byte array.
27+
`AvroUtils` provides methods `newGenericRecord` and `newSchema` to create avro records and schemas.
28+
29+
## Examples
30+
### Producer Example
31+
```
32+
DefaultMQProducer producer = new DefaultMQProducer("producer-group-json");
33+
producer.setNamesrvAddr("localhost:9876");
34+
producer.start();
35+
36+
// creating serializer for message body serializing
37+
RocketMQSerializer serializer = new RocketMQJsonSerializer<User>();
38+
39+
for (int i = 0; i < 100; i++) {
40+
User user = new User();
41+
user.setName("tom");
42+
user.setAge(i);
43+
44+
// creating message from user data.
45+
Message message = Messages.newMessage("topic-json", user, serializer);
46+
SendResult result = producer.send(message);
47+
System.out.print(result.getSendStatus() + " " + i + "\n");
48+
49+
Thread.sleep(1000);
50+
}
51+
```
52+
53+
### Consumer Example
54+
```
55+
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("consumer-group-json");
56+
consumer.setNamesrvAddr("localhost:9876");
57+
consumer.subscribe("topic-json", "*");
58+
59+
// creating deserializer for message body deserializing
60+
RocketMQDeserializer deserializer = new RocketMQJsonDeserializer<>(User.class);
61+
62+
consumer.registerMessageListener(new MessageListenerConcurrently() {
63+
@Override
64+
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list,
65+
ConsumeConcurrentlyContext consumeConcurrentlyContext) {
66+
for (MessageExt messageExt : list) {
67+
// getting data from message.
68+
User user = Messages.getMessageBody(messageExt, deserializer);
69+
System.out.print(user.getName() + ":" + user.getAge() + "\n");
70+
}
71+
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
72+
}
73+
});
74+
75+
consumer.start();
76+
```
77+
78+
## Internals
79+
`rocketmq-serializer-avro` is powered by Apache Avro, and `rocketmq-serializer-json` is powered by fastjson.
80+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.rocketmq</groupId>
24+
<artifactId>rocketmq-serializer-avro</artifactId>
25+
<version>0.0.1-SNAPSHOT</version>
26+
<packaging>jar</packaging>
27+
28+
<properties>
29+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30+
<!--maven properties -->
31+
<maven.test.skip>false</maven.test.skip>
32+
<maven.javadoc.skip>false</maven.javadoc.skip>
33+
<!-- compiler settings properties -->
34+
<maven.compiler.source>1.8</maven.compiler.source>
35+
<maven.compiler.target>1.8</maven.compiler.target>
36+
<rocketmq.version>4.2.0</rocketmq.version>
37+
<commons-lang.version>2.5</commons-lang.version>
38+
<avro.version>1.8.2</avro.version>
39+
</properties>
40+
41+
<dependencies>
42+
<dependency>
43+
<groupId>org.apache.rocketmq</groupId>
44+
<artifactId>rocketmq-serializer-core</artifactId>
45+
<version>${project.version}</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.apache.avro</groupId>
49+
<artifactId>avro</artifactId>
50+
<version>${avro.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.apache.rocketmq</groupId>
54+
<artifactId>rocketmq-client</artifactId>
55+
<version>${rocketmq.version}</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.apache.rocketmq</groupId>
59+
<artifactId>rocketmq-common</artifactId>
60+
<version>${rocketmq.version}</version>
61+
<exclusions>
62+
<exclusion>
63+
<groupId>io.netty</groupId>
64+
<artifactId>netty-tcnative</artifactId>
65+
</exclusion>
66+
</exclusions>
67+
</dependency>
68+
<dependency>
69+
<groupId>commons-lang</groupId>
70+
<artifactId>commons-lang</artifactId>
71+
<version>${commons-lang.version}</version>
72+
</dependency>
73+
74+
<!--test -->
75+
<dependency>
76+
<groupId>junit</groupId>
77+
<artifactId>junit</artifactId>
78+
<scope>test</scope>
79+
<version>4.12</version>
80+
</dependency>
81+
</dependencies>
82+
83+
<build>
84+
<plugins>
85+
<plugin>
86+
<artifactId>maven-compiler-plugin</artifactId>
87+
<version>3.5.1</version>
88+
<configuration>
89+
<source>${maven.compiler.source}</source>
90+
<target>${maven.compiler.target}</target>
91+
<encoding>UTF-8</encoding>
92+
<compilerVersion>${maven.compiler.source}</compilerVersion>
93+
<showDeprecation>true</showDeprecation>
94+
<showWarnings>true</showWarnings>
95+
</configuration>
96+
</plugin>
97+
<plugin>
98+
<groupId>org.apache.maven.plugins</groupId>
99+
<artifactId>maven-surefire-plugin</artifactId>
100+
<version>2.12.4</version>
101+
<configuration>
102+
<skipTests>${maven.test.skip}</skipTests>
103+
</configuration>
104+
</plugin>
105+
<plugin>
106+
<groupId>org.apache.rat</groupId>
107+
<artifactId>apache-rat-plugin</artifactId>
108+
<version>0.12</version>
109+
<configuration>
110+
<excludes>
111+
<exclude>README.md</exclude>
112+
</excludes>
113+
</configuration>
114+
</plugin>
115+
<plugin>
116+
<artifactId>maven-checkstyle-plugin</artifactId>
117+
<version>2.17</version>
118+
<executions>
119+
<execution>
120+
<id>verify</id>
121+
<phase>verify</phase>
122+
<configuration>
123+
<configLocation>../style/rmq_checkstyle.xml</configLocation>
124+
<encoding>UTF-8</encoding>
125+
<consoleOutput>true</consoleOutput>
126+
<failsOnError>true</failsOnError>
127+
<includeTestSourceDirectory>false</includeTestSourceDirectory>
128+
<includeTestResources>false</includeTestResources>
129+
</configuration>
130+
<goals>
131+
<goal>check</goal>
132+
</goals>
133+
</execution>
134+
</executions>
135+
</plugin>
136+
<plugin>
137+
<groupId>org.apache.avro</groupId>
138+
<artifactId>avro-maven-plugin</artifactId>
139+
<version>1.8.2</version>
140+
<executions>
141+
<execution>
142+
<phase>generate-sources</phase>
143+
<goals>
144+
<goal>schema</goal>
145+
</goals>
146+
<configuration>
147+
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
148+
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
149+
</configuration>
150+
</execution>
151+
</executions>
152+
</plugin>
153+
</plugins>
154+
</build>
155+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.avro;
19+
20+
import java.io.File;
21+
import java.io.IOException;
22+
import java.io.InputStream;
23+
import java.util.Map;
24+
25+
import org.apache.avro.Schema;
26+
import org.apache.avro.Schema.Parser;
27+
import org.apache.avro.generic.GenericData;
28+
import org.apache.avro.generic.GenericRecord;
29+
import org.apache.commons.lang.Validate;
30+
31+
public final class AvroUtils {
32+
private AvroUtils() {}
33+
34+
public static GenericRecord newGenericRecord(Schema schema) {
35+
Validate.notNull(schema);
36+
GenericRecord record = new GenericData.Record(schema);
37+
return record;
38+
}
39+
40+
public static GenericRecord newGenericRecordFromMap(Schema schema, Map<String, Object> map) {
41+
Validate.notNull(schema);
42+
Validate.notNull(map);
43+
GenericRecord record = new GenericData.Record(schema);
44+
map.forEach((k, v) -> {
45+
record.put(k, v);
46+
});
47+
return record;
48+
}
49+
50+
public static Schema newSchema(String schemaString) {
51+
Validate.notNull(schemaString);
52+
return new Parser().parse(schemaString);
53+
}
54+
55+
public static Schema newSchema(File schemaFile) {
56+
Validate.notNull(schemaFile);
57+
try {
58+
return new Parser().parse(schemaFile);
59+
} catch (IOException e) {
60+
throw new RuntimeException(e);
61+
}
62+
}
63+
64+
public static Schema newSchema(InputStream in) {
65+
Validate.notNull(in);
66+
try {
67+
return new Parser().parse(in);
68+
} catch (IOException e) {
69+
throw new RuntimeException(e);
70+
}
71+
}
72+
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.avro;
19+
20+
import java.util.Map;
21+
import java.util.concurrent.ConcurrentHashMap;
22+
23+
import org.apache.avro.Schema;
24+
25+
public class DefaultSchemaRegistry implements SchemaRegistry {
26+
private Map<String, Schema> schemas = new ConcurrentHashMap<>();
27+
28+
public void registerSchema(String id, String schemaString) {
29+
registerSchema(id, AvroUtils.newSchema(schemaString));
30+
}
31+
32+
@Override
33+
public void registerSchema(String id, Schema schema) {
34+
// override the old value
35+
schemas.put(id, schema);
36+
}
37+
38+
@Override
39+
public Schema getSchema(String id) {
40+
return schemas.get(id);
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.avro;
19+
20+
import java.io.IOException;
21+
22+
import org.apache.avro.Schema;
23+
import org.apache.avro.generic.GenericDatumReader;
24+
import org.apache.avro.generic.GenericRecord;
25+
import org.apache.avro.io.BinaryDecoder;
26+
import org.apache.avro.io.DatumReader;
27+
import org.apache.avro.io.DecoderFactory;
28+
import org.apache.commons.lang.Validate;
29+
import org.apache.rocketmq.serializer.RocketMQDeserializer;
30+
31+
public class RocketMQAvroDeserializer implements RocketMQDeserializer<GenericRecord> {
32+
private Schema schema;
33+
34+
public RocketMQAvroDeserializer(Schema schema) {
35+
this.schema = schema;
36+
}
37+
38+
@Override
39+
public GenericRecord deserialize(byte[] bytes) {
40+
Validate.notNull(bytes);
41+
42+
DatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
43+
BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(bytes, null);
44+
try {
45+
GenericRecord record = reader.read(null, decoder);
46+
return record;
47+
} catch (IOException e) {
48+
throw new RuntimeException(e);
49+
}
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.avro;
19+
20+
import java.io.ByteArrayOutputStream;
21+
import java.io.IOException;
22+
23+
import org.apache.avro.generic.GenericDatumWriter;
24+
import org.apache.avro.generic.GenericRecord;
25+
import org.apache.avro.io.DatumWriter;
26+
import org.apache.avro.io.Encoder;
27+
import org.apache.avro.io.EncoderFactory;
28+
import org.apache.commons.lang.Validate;
29+
import org.apache.rocketmq.serializer.RocketMQSerializer;
30+
31+
public class RocketMQAvroSerializer implements RocketMQSerializer<GenericRecord> {
32+
33+
@Override
34+
public byte[] serialize(GenericRecord obj) {
35+
Validate.notNull(obj);
36+
37+
DatumWriter<GenericRecord> writer = new GenericDatumWriter<>(obj.getSchema());
38+
ByteArrayOutputStream out = new ByteArrayOutputStream();
39+
Encoder encoder = EncoderFactory.get().directBinaryEncoder(out, null);
40+
41+
try {
42+
writer.write(obj, encoder);
43+
encoder.flush();
44+
byte[] bytes = out.toByteArray();
45+
out.close();
46+
return bytes;
47+
} catch (IOException e) {
48+
throw new RuntimeException(e);
49+
}
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.avro;
19+
20+
import java.io.IOException;
21+
22+
import org.apache.avro.Schema;
23+
import org.apache.avro.generic.GenericRecord;
24+
import org.apache.avro.io.BinaryDecoder;
25+
import org.apache.avro.io.DecoderFactory;
26+
import org.apache.avro.specific.SpecificDatumReader;
27+
import org.apache.commons.lang.Validate;
28+
import org.apache.rocketmq.serializer.RocketMQDeserializer;
29+
30+
public class RocketMQAvroSpecifiedDeserializer<T> implements RocketMQDeserializer<T> {
31+
private Schema schema;
32+
33+
public RocketMQAvroSpecifiedDeserializer(Schema schema) {
34+
this.schema = schema;
35+
}
36+
37+
@Override
38+
public T deserialize(byte[] bytes) {
39+
Validate.notNull(bytes);
40+
41+
SpecificDatumReader<GenericRecord> reader = new SpecificDatumReader<>(schema);
42+
BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(bytes, null);
43+
try {
44+
return (T) reader.read(null, decoder);
45+
} catch (IOException e) {
46+
throw new RuntimeException(e);
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.avro;
19+
20+
import java.io.ByteArrayOutputStream;
21+
import java.io.IOException;
22+
23+
import org.apache.avro.Schema;
24+
import org.apache.avro.io.DatumWriter;
25+
import org.apache.avro.io.Encoder;
26+
import org.apache.avro.io.EncoderFactory;
27+
import org.apache.avro.specific.SpecificDatumWriter;
28+
import org.apache.commons.lang.Validate;
29+
import org.apache.rocketmq.serializer.RocketMQSerializer;
30+
31+
public class RocketMQAvroSpecifiedSerializer<T> implements RocketMQSerializer<T> {
32+
private Schema schema;
33+
34+
public RocketMQAvroSpecifiedSerializer(Schema schema) {
35+
this.schema = schema;
36+
}
37+
38+
@Override
39+
public byte[] serialize(T obj) {
40+
Validate.notNull(obj);
41+
42+
DatumWriter<T> datumWriter = new SpecificDatumWriter<T>(schema);
43+
ByteArrayOutputStream out = new ByteArrayOutputStream();
44+
Encoder encoder = EncoderFactory.get().directBinaryEncoder(out, null);
45+
try {
46+
datumWriter.write(obj, encoder);
47+
encoder.flush();
48+
byte[] bytes = out.toByteArray();
49+
out.close();
50+
return bytes;
51+
} catch (IOException e) {
52+
throw new RuntimeException(e);
53+
}
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.avro;
19+
20+
import org.apache.avro.Schema;
21+
22+
public interface SchemaRegistry {
23+
24+
/**
25+
* Registering avro schema to registry center.
26+
* @param id schema id
27+
* @param schema avro schema
28+
*/
29+
void registerSchema(String id, Schema schema);
30+
31+
/**
32+
* Getting avro schema by schema id.
33+
* @param id schema id
34+
* @return avro schema
35+
*/
36+
Schema getSchema(String id);
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one or more
2+
// contributor license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright ownership.
4+
// The ASF licenses this file to You under the Apache License, Version 2.0
5+
// (the "License"); you may not use this file except in compliance with
6+
// the License. You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
{"namespace": "org.apache.rocketmq.serializer.avro",
17+
"type": "record",
18+
"name": "User",
19+
"fields": [
20+
{"name": "name", "type": "string"},
21+
{"name": "age", "type": "int"}
22+
]
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.avro;
19+
20+
import java.io.File;
21+
import java.util.HashMap;
22+
23+
import org.apache.avro.Schema;
24+
import org.apache.avro.generic.GenericRecord;
25+
import org.junit.Test;
26+
27+
import static org.junit.Assert.assertEquals;
28+
29+
public class RocketMQAvroSerializerTest {
30+
@Test
31+
public void testSerializeAndDeserialize() throws Exception {
32+
Schema schema = AvroUtils.newSchema(new File("src/test/avro/user.avsc"));
33+
RocketMQAvroSerializer avroSerializer = new RocketMQAvroSerializer();
34+
HashMap<String,Object> map = new HashMap<>();
35+
map.put("name", "tom");
36+
map.put("age", 16);
37+
GenericRecord obj = AvroUtils.newGenericRecordFromMap(schema, map);
38+
byte[] result = avroSerializer.serialize(obj);
39+
40+
RocketMQAvroDeserializer avroDeserializer = new RocketMQAvroDeserializer(schema);
41+
assertEquals(obj, avroDeserializer.deserialize(result));
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.avro;
19+
20+
import java.io.File;
21+
22+
import org.apache.avro.Schema;
23+
import org.junit.Test;
24+
import static org.junit.Assert.assertEquals;
25+
26+
public class RocketMQAvroSpecifiedSerializerTest {
27+
@Test
28+
public void testSerializeAndDeserialize() throws Exception {
29+
Schema schema = AvroUtils.newSchema(new File("src/test/avro/user.avsc"));
30+
RocketMQAvroSpecifiedSerializer<User> avroSpecifiedSerializer = new RocketMQAvroSpecifiedSerializer<>(schema);
31+
User user = new User();
32+
user.setName("tom");
33+
user.setAge(16);
34+
byte[] result = avroSpecifiedSerializer.serialize(user);
35+
36+
RocketMQAvroSpecifiedDeserializer<User> avroSpecifiedDeserializer = new RocketMQAvroSpecifiedDeserializer<>(schema);
37+
assertEquals(user, avroSpecifiedDeserializer.deserialize(result));
38+
}
39+
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
/**
19+
* Autogenerated by Avro
20+
*
21+
* DO NOT EDIT DIRECTLY
22+
*/
23+
package org.apache.rocketmq.serializer.avro;
24+
25+
import org.apache.avro.message.BinaryMessageDecoder;
26+
import org.apache.avro.message.BinaryMessageEncoder;
27+
import org.apache.avro.message.SchemaStore;
28+
import org.apache.avro.specific.SpecificData;
29+
30+
@SuppressWarnings("all")
31+
@org.apache.avro.specific.AvroGenerated
32+
public class User extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
33+
private static final long serialVersionUID = 3860209681772090087L;
34+
public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"org.apache.rocketmq.serializer.avro\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"age\",\"type\":\"int\"}]}");
35+
public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
36+
37+
private static SpecificData MODEL$ = new SpecificData();
38+
39+
private static final BinaryMessageEncoder<User> ENCODER =
40+
new BinaryMessageEncoder<User>(MODEL$, SCHEMA$);
41+
42+
private static final BinaryMessageDecoder<User> DECODER =
43+
new BinaryMessageDecoder<User>(MODEL$, SCHEMA$);
44+
45+
/**
46+
* Return the BinaryMessageDecoder instance used by this class.
47+
*/
48+
public static BinaryMessageDecoder<User> getDecoder() {
49+
return DECODER;
50+
}
51+
52+
/**
53+
* Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}.
54+
* @param resolver a {@link SchemaStore} used to find schemas by fingerprint
55+
*/
56+
public static BinaryMessageDecoder<User> createDecoder(SchemaStore resolver) {
57+
return new BinaryMessageDecoder<User>(MODEL$, SCHEMA$, resolver);
58+
}
59+
60+
/** Serializes this User to a ByteBuffer. */
61+
public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
62+
return ENCODER.encode(this);
63+
}
64+
65+
/** Deserializes a User from a ByteBuffer. */
66+
public static User fromByteBuffer(
67+
java.nio.ByteBuffer b) throws java.io.IOException {
68+
return DECODER.decode(b);
69+
}
70+
71+
@Deprecated public CharSequence name;
72+
@Deprecated public int age;
73+
74+
/**
75+
* Default constructor. Note that this does not initialize fields
76+
* to their default values from the schema. If that is desired then
77+
* one should use <code>newBuilder()</code>.
78+
*/
79+
public User() {}
80+
81+
/**
82+
* All-args constructor.
83+
* @param name The new value for name
84+
* @param age The new value for age
85+
*/
86+
public User(CharSequence name, Integer age) {
87+
this.name = name;
88+
this.age = age;
89+
}
90+
91+
public org.apache.avro.Schema getSchema() { return SCHEMA$; }
92+
// Used by DatumWriter. Applications should not call.
93+
public Object get(int field$) {
94+
switch (field$) {
95+
case 0: return name;
96+
case 1: return age;
97+
default: throw new org.apache.avro.AvroRuntimeException("Bad index");
98+
}
99+
}
100+
101+
// Used by DatumReader. Applications should not call.
102+
@SuppressWarnings(value="unchecked")
103+
public void put(int field$, Object value$) {
104+
switch (field$) {
105+
case 0: name = (CharSequence)value$; break;
106+
case 1: age = (Integer)value$; break;
107+
default: throw new org.apache.avro.AvroRuntimeException("Bad index");
108+
}
109+
}
110+
111+
/**
112+
* Gets the value of the 'name' field.
113+
* @return The value of the 'name' field.
114+
*/
115+
public CharSequence getName() {
116+
return name;
117+
}
118+
119+
/**
120+
* Sets the value of the 'name' field.
121+
* @param value the value to set.
122+
*/
123+
public void setName(CharSequence value) {
124+
this.name = value;
125+
}
126+
127+
/**
128+
* Gets the value of the 'age' field.
129+
* @return The value of the 'age' field.
130+
*/
131+
public Integer getAge() {
132+
return age;
133+
}
134+
135+
/**
136+
* Sets the value of the 'age' field.
137+
* @param value the value to set.
138+
*/
139+
public void setAge(Integer value) {
140+
this.age = value;
141+
}
142+
143+
/**
144+
* Creates a new User RecordBuilder.
145+
* @return A new User RecordBuilder
146+
*/
147+
public static User.Builder newBuilder() {
148+
return new User.Builder();
149+
}
150+
151+
/**
152+
* Creates a new User RecordBuilder by copying an existing Builder.
153+
* @param other The existing builder to copy.
154+
* @return A new User RecordBuilder
155+
*/
156+
public static User.Builder newBuilder(User.Builder other) {
157+
return new User.Builder(other);
158+
}
159+
160+
/**
161+
* Creates a new User RecordBuilder by copying an existing User instance.
162+
* @param other The existing instance to copy.
163+
* @return A new User RecordBuilder
164+
*/
165+
public static User.Builder newBuilder(User other) {
166+
return new User.Builder(other);
167+
}
168+
169+
/**
170+
* RecordBuilder for User instances.
171+
*/
172+
public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<User>
173+
implements org.apache.avro.data.RecordBuilder<User> {
174+
175+
private CharSequence name;
176+
private int age;
177+
178+
/** Creates a new Builder */
179+
private Builder() {
180+
super(SCHEMA$);
181+
}
182+
183+
/**
184+
* Creates a Builder by copying an existing Builder.
185+
* @param other The existing Builder to copy.
186+
*/
187+
private Builder(User.Builder other) {
188+
super(other);
189+
if (isValidValue(fields()[0], other.name)) {
190+
this.name = data().deepCopy(fields()[0].schema(), other.name);
191+
fieldSetFlags()[0] = true;
192+
}
193+
if (isValidValue(fields()[1], other.age)) {
194+
this.age = data().deepCopy(fields()[1].schema(), other.age);
195+
fieldSetFlags()[1] = true;
196+
}
197+
}
198+
199+
/**
200+
* Creates a Builder by copying an existing User instance
201+
* @param other The existing instance to copy.
202+
*/
203+
private Builder(User other) {
204+
super(SCHEMA$);
205+
if (isValidValue(fields()[0], other.name)) {
206+
this.name = data().deepCopy(fields()[0].schema(), other.name);
207+
fieldSetFlags()[0] = true;
208+
}
209+
if (isValidValue(fields()[1], other.age)) {
210+
this.age = data().deepCopy(fields()[1].schema(), other.age);
211+
fieldSetFlags()[1] = true;
212+
}
213+
}
214+
215+
/**
216+
* Gets the value of the 'name' field.
217+
* @return The value.
218+
*/
219+
public CharSequence getName() {
220+
return name;
221+
}
222+
223+
/**
224+
* Sets the value of the 'name' field.
225+
* @param value The value of 'name'.
226+
* @return This builder.
227+
*/
228+
public User.Builder setName(CharSequence value) {
229+
validate(fields()[0], value);
230+
this.name = value;
231+
fieldSetFlags()[0] = true;
232+
return this;
233+
}
234+
235+
/**
236+
* Checks whether the 'name' field has been set.
237+
* @return True if the 'name' field has been set, false otherwise.
238+
*/
239+
public boolean hasName() {
240+
return fieldSetFlags()[0];
241+
}
242+
243+
244+
/**
245+
* Clears the value of the 'name' field.
246+
* @return This builder.
247+
*/
248+
public User.Builder clearName() {
249+
name = null;
250+
fieldSetFlags()[0] = false;
251+
return this;
252+
}
253+
254+
/**
255+
* Gets the value of the 'age' field.
256+
* @return The value.
257+
*/
258+
public Integer getAge() {
259+
return age;
260+
}
261+
262+
/**
263+
* Sets the value of the 'age' field.
264+
* @param value The value of 'age'.
265+
* @return This builder.
266+
*/
267+
public User.Builder setAge(int value) {
268+
validate(fields()[1], value);
269+
this.age = value;
270+
fieldSetFlags()[1] = true;
271+
return this;
272+
}
273+
274+
/**
275+
* Checks whether the 'age' field has been set.
276+
* @return True if the 'age' field has been set, false otherwise.
277+
*/
278+
public boolean hasAge() {
279+
return fieldSetFlags()[1];
280+
}
281+
282+
283+
/**
284+
* Clears the value of the 'age' field.
285+
* @return This builder.
286+
*/
287+
public User.Builder clearAge() {
288+
fieldSetFlags()[1] = false;
289+
return this;
290+
}
291+
292+
@Override
293+
@SuppressWarnings("unchecked")
294+
public User build() {
295+
try {
296+
User record = new User();
297+
record.name = fieldSetFlags()[0] ? this.name : (CharSequence) defaultValue(fields()[0]);
298+
record.age = fieldSetFlags()[1] ? this.age : (Integer) defaultValue(fields()[1]);
299+
return record;
300+
} catch (Exception e) {
301+
throw new org.apache.avro.AvroRuntimeException(e);
302+
}
303+
}
304+
}
305+
306+
@SuppressWarnings("unchecked")
307+
private static final org.apache.avro.io.DatumWriter<User>
308+
WRITER$ = (org.apache.avro.io.DatumWriter<User>)MODEL$.createDatumWriter(SCHEMA$);
309+
310+
@Override public void writeExternal(java.io.ObjectOutput out)
311+
throws java.io.IOException {
312+
WRITER$.write(this, SpecificData.getEncoder(out));
313+
}
314+
315+
@SuppressWarnings("unchecked")
316+
private static final org.apache.avro.io.DatumReader<User>
317+
READER$ = (org.apache.avro.io.DatumReader<User>)MODEL$.createDatumReader(SCHEMA$);
318+
319+
@Override public void readExternal(java.io.ObjectInput in)
320+
throws java.io.IOException {
321+
READER$.read(this, SpecificData.getDecoder(in));
322+
}
323+
324+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.rocketmq</groupId>
24+
<artifactId>rocketmq-serializer-core</artifactId>
25+
<version>0.0.1-SNAPSHOT</version>
26+
<packaging>jar</packaging>
27+
28+
<properties>
29+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30+
<!--maven properties -->
31+
<maven.test.skip>false</maven.test.skip>
32+
<maven.javadoc.skip>false</maven.javadoc.skip>
33+
<!-- compiler settings properties -->
34+
<maven.compiler.source>1.8</maven.compiler.source>
35+
<maven.compiler.target>1.8</maven.compiler.target>
36+
<rocketmq.version>4.2.0</rocketmq.version>
37+
<commons-lang.version>2.5</commons-lang.version>
38+
</properties>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.apache.rocketmq</groupId>
43+
<artifactId>rocketmq-client</artifactId>
44+
<version>${rocketmq.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.apache.rocketmq</groupId>
48+
<artifactId>rocketmq-common</artifactId>
49+
<version>${rocketmq.version}</version>
50+
<exclusions>
51+
<exclusion>
52+
<groupId>io.netty</groupId>
53+
<artifactId>netty-tcnative</artifactId>
54+
</exclusion>
55+
</exclusions>
56+
</dependency>
57+
<dependency>
58+
<groupId>commons-lang</groupId>
59+
<artifactId>commons-lang</artifactId>
60+
<version>${commons-lang.version}</version>
61+
</dependency>
62+
63+
<!--test -->
64+
<dependency>
65+
<groupId>junit</groupId>
66+
<artifactId>junit</artifactId>
67+
<scope>test</scope>
68+
<version>4.12</version>
69+
</dependency>
70+
</dependencies>
71+
72+
<build>
73+
<plugins>
74+
<plugin>
75+
<artifactId>maven-compiler-plugin</artifactId>
76+
<version>3.5.1</version>
77+
<configuration>
78+
<source>${maven.compiler.source}</source>
79+
<target>${maven.compiler.target}</target>
80+
<encoding>UTF-8</encoding>
81+
<compilerVersion>${maven.compiler.source}</compilerVersion>
82+
<showDeprecation>true</showDeprecation>
83+
<showWarnings>true</showWarnings>
84+
</configuration>
85+
</plugin>
86+
<plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-surefire-plugin</artifactId>
89+
<version>2.12.4</version>
90+
<configuration>
91+
<skipTests>${maven.test.skip}</skipTests>
92+
</configuration>
93+
</plugin>
94+
<plugin>
95+
<groupId>org.apache.rat</groupId>
96+
<artifactId>apache-rat-plugin</artifactId>
97+
<version>0.12</version>
98+
<configuration>
99+
<excludes>
100+
<exclude>README.md</exclude>
101+
</excludes>
102+
</configuration>
103+
</plugin>
104+
<plugin>
105+
<artifactId>maven-checkstyle-plugin</artifactId>
106+
<version>2.17</version>
107+
<executions>
108+
<execution>
109+
<id>verify</id>
110+
<phase>verify</phase>
111+
<configuration>
112+
<configLocation>../style/rmq_checkstyle.xml</configLocation>
113+
<encoding>UTF-8</encoding>
114+
<consoleOutput>true</consoleOutput>
115+
<failsOnError>true</failsOnError>
116+
<includeTestSourceDirectory>false</includeTestSourceDirectory>
117+
<includeTestResources>false</includeTestResources>
118+
</configuration>
119+
<goals>
120+
<goal>check</goal>
121+
</goals>
122+
</execution>
123+
</executions>
124+
</plugin>
125+
</plugins>
126+
</build>
127+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer;
19+
20+
import org.apache.commons.lang.Validate;
21+
import org.apache.rocketmq.common.message.Message;
22+
import org.apache.rocketmq.serializer.impl.RocketMQStringDeserializer;
23+
import org.apache.rocketmq.serializer.impl.RocketMQStringSerializer;
24+
25+
/**
26+
* Tool class for message body serializing and deserializing.
27+
* Using string Serializer and Deserializer by default.
28+
*/
29+
public final class Messages {
30+
public static RocketMQSerializer defaultSerializer = new RocketMQStringSerializer();
31+
public static RocketMQDeserializer defaultDeserializer = new RocketMQStringDeserializer();
32+
33+
private Messages() {}
34+
35+
public static Message newMessage(String topic, Object obj) {
36+
return newMessage(topic, obj, defaultSerializer);
37+
}
38+
39+
public static Message newMessage(String topic, String tag, Object obj) {
40+
return newMessage(topic, tag, obj, defaultSerializer);
41+
}
42+
43+
public static Message newMessage(String topic, String tag, String key, Object obj) {
44+
return newMessage(topic, tag, key, obj, defaultSerializer);
45+
}
46+
47+
public static Message newMessage(String topic, Object obj, RocketMQSerializer serializer) {
48+
Validate.notNull(topic);
49+
Validate.notNull(obj);
50+
Validate.notNull(serializer);
51+
return new Message(topic, serializer.serialize(obj));
52+
}
53+
54+
public static Message newMessage(String topic, String tag, Object obj, RocketMQSerializer serializer) {
55+
Validate.notNull(topic);
56+
Validate.notNull(tag);
57+
Validate.notNull(obj);
58+
Validate.notNull(serializer);
59+
return new Message(topic, tag, serializer.serialize(obj));
60+
}
61+
62+
public static Message newMessage(String topic, String tag, String key, Object obj, RocketMQSerializer serializer) {
63+
Validate.notNull(topic);
64+
Validate.notNull(tag);
65+
Validate.notNull(key);
66+
Validate.notNull(obj);
67+
Validate.notNull(serializer);
68+
return new Message(topic, tag, key, serializer.serialize(obj));
69+
}
70+
71+
public static <T> T getMessageBody(Message message) {
72+
return getMessageBody(message, defaultDeserializer);
73+
}
74+
75+
public static <T> T getMessageBody(Message message, RocketMQDeserializer deserializer) {
76+
Validate.notNull(message);
77+
Validate.notNull(deserializer);
78+
return (T) deserializer.deserialize(message.getBody());
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer;
19+
20+
public interface RocketMQDeserializer<T> {
21+
22+
/**
23+
* Deserializing bytes to object.
24+
* @param bytes bytes need deserializing
25+
* @return object
26+
*/
27+
T deserialize(byte[] bytes);
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer;
19+
20+
public interface RocketMQSerializer<T> {
21+
22+
/**
23+
* Serializing object to bytes.
24+
* @param obj object need serializing
25+
* @return bytes
26+
*/
27+
byte[] serialize(T obj);
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.impl;
19+
20+
import java.nio.charset.StandardCharsets;
21+
22+
import org.apache.commons.lang.Validate;
23+
import org.apache.rocketmq.serializer.RocketMQDeserializer;
24+
25+
public class RocketMQStringDeserializer implements RocketMQDeserializer<String> {
26+
@Override
27+
public String deserialize(byte[] bytes) {
28+
Validate.notNull(bytes);
29+
return new String(bytes, StandardCharsets.UTF_8);
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.impl;
19+
20+
import java.nio.charset.StandardCharsets;
21+
22+
import org.apache.commons.lang.Validate;
23+
import org.apache.rocketmq.serializer.RocketMQSerializer;
24+
25+
public class RocketMQStringSerializer implements RocketMQSerializer<String> {
26+
@Override
27+
public byte[] serialize(String obj) {
28+
Validate.notNull(obj);
29+
return obj.getBytes(StandardCharsets.UTF_8);
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.impl;
19+
20+
import org.junit.Test;
21+
22+
import static org.junit.Assert.*;
23+
24+
public class RocketMQStringSerializerTest {
25+
@Test
26+
public void testSerializeAndDeserialize() throws Exception {
27+
RocketMQStringSerializer stringSerializer = new RocketMQStringSerializer();
28+
String obj = new String("hello rocket!");
29+
byte[] result = stringSerializer.serialize(obj);
30+
31+
RocketMQStringDeserializer stringDeserializer = new RocketMQStringDeserializer();
32+
assertEquals(obj, stringDeserializer.deserialize(result));
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.rocketmq</groupId>
24+
<artifactId>rocketmq-serializer-examples</artifactId>
25+
<version>0.0.1-SNAPSHOT</version>
26+
<packaging>jar</packaging>
27+
28+
<properties>
29+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30+
<!--maven properties -->
31+
<maven.test.skip>false</maven.test.skip>
32+
<maven.javadoc.skip>false</maven.javadoc.skip>
33+
<!-- compiler settings properties -->
34+
<maven.compiler.source>1.8</maven.compiler.source>
35+
<maven.compiler.target>1.8</maven.compiler.target>
36+
<rocketmq.version>4.2.0</rocketmq.version>
37+
<commons-lang.version>2.5</commons-lang.version>
38+
</properties>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.apache.rocketmq</groupId>
43+
<artifactId>rocketmq-serializer-core</artifactId>
44+
<version>${project.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.apache.rocketmq</groupId>
48+
<artifactId>rocketmq-serializer-json</artifactId>
49+
<version>${project.version}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.apache.rocketmq</groupId>
53+
<artifactId>rocketmq-serializer-avro</artifactId>
54+
<version>${project.version}</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.apache.rocketmq</groupId>
58+
<artifactId>rocketmq-client</artifactId>
59+
<version>${rocketmq.version}</version>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.apache.rocketmq</groupId>
63+
<artifactId>rocketmq-common</artifactId>
64+
<version>${rocketmq.version}</version>
65+
<exclusions>
66+
<exclusion>
67+
<groupId>io.netty</groupId>
68+
<artifactId>netty-tcnative</artifactId>
69+
</exclusion>
70+
</exclusions>
71+
</dependency>
72+
<dependency>
73+
<groupId>commons-lang</groupId>
74+
<artifactId>commons-lang</artifactId>
75+
<version>${commons-lang.version}</version>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.apache.rocketmq</groupId>
79+
<artifactId>rocketmq-namesrv</artifactId>
80+
<version>${rocketmq.version}</version>
81+
</dependency>
82+
<dependency>
83+
<groupId>org.apache.rocketmq</groupId>
84+
<artifactId>rocketmq-broker</artifactId>
85+
<version>${rocketmq.version}</version>
86+
</dependency>
87+
</dependencies>
88+
89+
<build>
90+
<plugins>
91+
<plugin>
92+
<artifactId>maven-compiler-plugin</artifactId>
93+
<version>3.5.1</version>
94+
<configuration>
95+
<source>${maven.compiler.source}</source>
96+
<target>${maven.compiler.target}</target>
97+
<encoding>UTF-8</encoding>
98+
<compilerVersion>${maven.compiler.source}</compilerVersion>
99+
<showDeprecation>true</showDeprecation>
100+
<showWarnings>true</showWarnings>
101+
</configuration>
102+
</plugin>
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-surefire-plugin</artifactId>
106+
<version>2.12.4</version>
107+
<configuration>
108+
<skipTests>${maven.test.skip}</skipTests>
109+
</configuration>
110+
</plugin>
111+
<plugin>
112+
<groupId>org.apache.rat</groupId>
113+
<artifactId>apache-rat-plugin</artifactId>
114+
<version>0.12</version>
115+
<configuration>
116+
<excludes>
117+
<exclude>README.md</exclude>
118+
</excludes>
119+
</configuration>
120+
</plugin>
121+
<plugin>
122+
<artifactId>maven-checkstyle-plugin</artifactId>
123+
<version>2.17</version>
124+
<executions>
125+
<execution>
126+
<id>verify</id>
127+
<phase>verify</phase>
128+
<configuration>
129+
<configLocation>../style/rmq_checkstyle.xml</configLocation>
130+
<encoding>UTF-8</encoding>
131+
<consoleOutput>true</consoleOutput>
132+
<failsOnError>true</failsOnError>
133+
<includeTestSourceDirectory>false</includeTestSourceDirectory>
134+
<includeTestResources>false</includeTestResources>
135+
</configuration>
136+
<goals>
137+
<goal>check</goal>
138+
</goals>
139+
</execution>
140+
</executions>
141+
</plugin>
142+
</plugins>
143+
</build>
144+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer;
19+
20+
import java.util.List;
21+
22+
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
23+
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
24+
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
25+
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
26+
import org.apache.rocketmq.common.message.MessageExt;
27+
import org.apache.rocketmq.serializer.json.RocketMQJsonDeserializer;
28+
29+
public class JsonConsumer {
30+
public static void main(String[] args) throws Exception {
31+
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("consumer-group-json");
32+
consumer.setNamesrvAddr("localhost:9876");
33+
consumer.subscribe("topic-json", "*");
34+
35+
// creating deserializer for message body deserializing
36+
RocketMQDeserializer deserializer = new RocketMQJsonDeserializer<>(User.class);
37+
38+
consumer.registerMessageListener(new MessageListenerConcurrently() {
39+
@Override
40+
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list,
41+
ConsumeConcurrentlyContext consumeConcurrentlyContext) {
42+
for (MessageExt messageExt : list) {
43+
// getting data from message.
44+
User user = Messages.getMessageBody(messageExt, deserializer);
45+
System.out.print(user.getName() + ":" + user.getAge() + "\n");
46+
}
47+
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
48+
}
49+
});
50+
51+
consumer.start();
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer;
19+
20+
import org.apache.rocketmq.client.producer.DefaultMQProducer;
21+
import org.apache.rocketmq.client.producer.SendResult;
22+
import org.apache.rocketmq.common.message.Message;
23+
import org.apache.rocketmq.serializer.json.RocketMQJsonSerializer;
24+
25+
public class JsonProducer {
26+
public static void main(String[] args) throws Exception {
27+
DefaultMQProducer producer = new DefaultMQProducer("producer-group-json");
28+
producer.setNamesrvAddr("localhost:9876");
29+
producer.start();
30+
31+
// creating serializer for message body serializing
32+
RocketMQSerializer serializer = new RocketMQJsonSerializer<User>();
33+
34+
for (int i = 0; i < 100; i++) {
35+
User user = new User();
36+
user.setName("tom");
37+
user.setAge(i);
38+
39+
// creating message from user data.
40+
Message message = Messages.newMessage("topic-json", user, serializer);
41+
SendResult result = producer.send(message);
42+
System.out.print(result.getSendStatus() + " " + i + "\n");
43+
44+
Thread.sleep(1000);
45+
}
46+
}
47+
}
48+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer;
19+
20+
import org.apache.rocketmq.broker.BrokerController;
21+
import org.apache.rocketmq.common.BrokerConfig;
22+
import org.apache.rocketmq.common.MQVersion;
23+
import org.apache.rocketmq.common.MixAll;
24+
import org.apache.rocketmq.common.namesrv.NamesrvConfig;
25+
import org.apache.rocketmq.namesrv.NamesrvController;
26+
import org.apache.rocketmq.remoting.netty.NettyClientConfig;
27+
import org.apache.rocketmq.remoting.netty.NettyServerConfig;
28+
import org.apache.rocketmq.remoting.protocol.RemotingCommand;
29+
import org.apache.rocketmq.store.config.MessageStoreConfig;
30+
31+
public class RocketMQLocalCluster {
32+
private NamesrvController namesrvController;
33+
private BrokerController brokerController;
34+
private String nameserverAddr = "localhost:9876";
35+
36+
public void startupServer() throws Exception {
37+
//start nameserver
38+
startNamesrv();
39+
//start broker
40+
startBroker();
41+
}
42+
43+
public void shutdownServer() {
44+
if (brokerController != null) {
45+
brokerController.shutdown();
46+
}
47+
48+
if (namesrvController != null) {
49+
namesrvController.shutdown();
50+
}
51+
}
52+
53+
public String getNameServerAddr() {
54+
return nameserverAddr;
55+
}
56+
57+
private void startNamesrv() throws Exception {
58+
NamesrvConfig namesrvConfig = new NamesrvConfig();
59+
NettyServerConfig nettyServerConfig = new NettyServerConfig();
60+
nettyServerConfig.setListenPort(9876);
61+
62+
namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);
63+
boolean initResult = namesrvController.initialize();
64+
if (!initResult) {
65+
namesrvController.shutdown();
66+
throw new Exception("Namesvr init failure!");
67+
}
68+
namesrvController.start();
69+
}
70+
71+
private void startBroker() throws Exception {
72+
System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
73+
74+
BrokerConfig brokerConfig = new BrokerConfig();
75+
brokerConfig.setNamesrvAddr(nameserverAddr);
76+
brokerConfig.setBrokerId(MixAll.MASTER_ID);
77+
NettyServerConfig nettyServerConfig = new NettyServerConfig();
78+
nettyServerConfig.setListenPort(10911);
79+
NettyClientConfig nettyClientConfig = new NettyClientConfig();
80+
MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
81+
82+
brokerController = new BrokerController(brokerConfig, nettyServerConfig, nettyClientConfig, messageStoreConfig);
83+
boolean initResult = brokerController.initialize();
84+
if (!initResult) {
85+
brokerController.shutdown();
86+
throw new Exception("Broker init failure!");
87+
}
88+
brokerController.start();
89+
}
90+
91+
public static void main(String[] args) throws Exception {
92+
new RocketMQLocalCluster().startupServer();
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer;
19+
20+
import java.util.List;
21+
22+
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
23+
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
24+
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
25+
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
26+
import org.apache.rocketmq.common.message.MessageExt;
27+
28+
public class SimpleConsumer {
29+
public static void main(String[] args) throws Exception {
30+
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("consumer-group-simple");
31+
consumer.setNamesrvAddr("localhost:9876");
32+
consumer.subscribe("topic", "*");
33+
34+
consumer.registerMessageListener(new MessageListenerConcurrently() {
35+
@Override
36+
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list,
37+
ConsumeConcurrentlyContext consumeConcurrentlyContext) {
38+
for (MessageExt messageExt : list) {
39+
// getting data from message. using string deserializer by default.
40+
String data = Messages.getMessageBody(messageExt);
41+
System.out.print("data:" + data + "\n");
42+
}
43+
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
44+
}
45+
});
46+
47+
consumer.start();
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer;
19+
20+
import org.apache.rocketmq.client.producer.DefaultMQProducer;
21+
import org.apache.rocketmq.client.producer.SendResult;
22+
import org.apache.rocketmq.common.message.Message;
23+
24+
public class SimpleProducer {
25+
public static void main(String[] args) throws Exception {
26+
DefaultMQProducer producer = new DefaultMQProducer("producer-group-simple");
27+
producer.setNamesrvAddr("localhost:9876");
28+
producer.start();
29+
30+
for (int i = 0; i < 100; i++) {
31+
// creating message from user data. using string serializer by default.
32+
Message message = Messages.newMessage("topic", "say hello to rocket! " + i);
33+
SendResult result = producer.send(message);
34+
System.out.print(result.getSendStatus() + " " + i + "\n");
35+
36+
Thread.sleep(1000);
37+
}
38+
}
39+
}
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer;
19+
20+
public class User {
21+
private String name;
22+
private int age;
23+
24+
public String getName() {
25+
return name;
26+
}
27+
28+
public void setName(String name) {
29+
this.name = name;
30+
}
31+
32+
public int getAge() {
33+
return age;
34+
}
35+
36+
public void setAge(int age) {
37+
this.age = age;
38+
}
39+
40+
@Override
41+
public boolean equals(Object obj) {
42+
if (obj == this) {
43+
return true;
44+
}
45+
if (obj instanceof User) {
46+
User u = (User) obj;
47+
if (u.name.equals(this.name) && u.age == this.age) {
48+
return true;
49+
}
50+
return false;
51+
}
52+
return false;
53+
}
54+
55+
@Override
56+
public int hashCode() {
57+
return super.hashCode();
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.rocketmq</groupId>
24+
<artifactId>rocketmq-serializer-json</artifactId>
25+
<version>0.0.1-SNAPSHOT</version>
26+
<packaging>jar</packaging>
27+
28+
<properties>
29+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30+
<!--maven properties -->
31+
<maven.test.skip>false</maven.test.skip>
32+
<maven.javadoc.skip>false</maven.javadoc.skip>
33+
<!-- compiler settings properties -->
34+
<maven.compiler.source>1.8</maven.compiler.source>
35+
<maven.compiler.target>1.8</maven.compiler.target>
36+
<rocketmq.version>4.2.0</rocketmq.version>
37+
<commons-lang.version>2.5</commons-lang.version>
38+
<fastjson.version>1.2.44</fastjson.version>
39+
</properties>
40+
41+
<dependencies>
42+
<dependency>
43+
<groupId>org.apache.rocketmq</groupId>
44+
<artifactId>rocketmq-serializer-core</artifactId>
45+
<version>${project.version}</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>com.alibaba</groupId>
49+
<artifactId>fastjson</artifactId>
50+
<version>${fastjson.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.apache.rocketmq</groupId>
54+
<artifactId>rocketmq-client</artifactId>
55+
<version>${rocketmq.version}</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.apache.rocketmq</groupId>
59+
<artifactId>rocketmq-common</artifactId>
60+
<version>${rocketmq.version}</version>
61+
<exclusions>
62+
<exclusion>
63+
<groupId>io.netty</groupId>
64+
<artifactId>netty-tcnative</artifactId>
65+
</exclusion>
66+
</exclusions>
67+
</dependency>
68+
<dependency>
69+
<groupId>commons-lang</groupId>
70+
<artifactId>commons-lang</artifactId>
71+
<version>${commons-lang.version}</version>
72+
</dependency>
73+
74+
<!--test -->
75+
<dependency>
76+
<groupId>junit</groupId>
77+
<artifactId>junit</artifactId>
78+
<scope>test</scope>
79+
<version>4.12</version>
80+
</dependency>
81+
</dependencies>
82+
83+
<build>
84+
<plugins>
85+
<plugin>
86+
<artifactId>maven-compiler-plugin</artifactId>
87+
<version>3.5.1</version>
88+
<configuration>
89+
<source>${maven.compiler.source}</source>
90+
<target>${maven.compiler.target}</target>
91+
<encoding>UTF-8</encoding>
92+
<compilerVersion>${maven.compiler.source}</compilerVersion>
93+
<showDeprecation>true</showDeprecation>
94+
<showWarnings>true</showWarnings>
95+
</configuration>
96+
</plugin>
97+
<plugin>
98+
<groupId>org.apache.maven.plugins</groupId>
99+
<artifactId>maven-surefire-plugin</artifactId>
100+
<version>2.12.4</version>
101+
<configuration>
102+
<skipTests>${maven.test.skip}</skipTests>
103+
</configuration>
104+
</plugin>
105+
<plugin>
106+
<groupId>org.apache.rat</groupId>
107+
<artifactId>apache-rat-plugin</artifactId>
108+
<version>0.12</version>
109+
<configuration>
110+
<excludes>
111+
<exclude>README.md</exclude>
112+
</excludes>
113+
</configuration>
114+
</plugin>
115+
<plugin>
116+
<artifactId>maven-checkstyle-plugin</artifactId>
117+
<version>2.17</version>
118+
<executions>
119+
<execution>
120+
<id>verify</id>
121+
<phase>verify</phase>
122+
<configuration>
123+
<configLocation>../style/rmq_checkstyle.xml</configLocation>
124+
<encoding>UTF-8</encoding>
125+
<consoleOutput>true</consoleOutput>
126+
<failsOnError>true</failsOnError>
127+
<includeTestSourceDirectory>false</includeTestSourceDirectory>
128+
<includeTestResources>false</includeTestResources>
129+
</configuration>
130+
<goals>
131+
<goal>check</goal>
132+
</goals>
133+
</execution>
134+
</executions>
135+
</plugin>
136+
</plugins>
137+
</build>
138+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.json;
19+
20+
import java.nio.charset.StandardCharsets;
21+
22+
import com.alibaba.fastjson.JSON;
23+
24+
import org.apache.commons.lang.Validate;
25+
import org.apache.rocketmq.serializer.RocketMQDeserializer;
26+
27+
public class RocketMQJsonDeserializer<T> implements RocketMQDeserializer<T> {
28+
private Class<T> clazz;
29+
30+
public RocketMQJsonDeserializer(Class<T> clazz) {
31+
this.clazz = clazz;
32+
}
33+
34+
@Override
35+
public T deserialize(byte[] bytes) {
36+
Validate.notNull(bytes);
37+
return JSON.parseObject(new String(bytes, StandardCharsets.UTF_8), clazz);
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.json;
19+
20+
import java.nio.charset.StandardCharsets;
21+
22+
import com.alibaba.fastjson.JSON;
23+
24+
import org.apache.commons.lang.Validate;
25+
import org.apache.rocketmq.serializer.RocketMQSerializer;
26+
27+
public class RocketMQJsonSerializer<T> implements RocketMQSerializer<T> {
28+
@Override
29+
public byte[] serialize(T obj) {
30+
Validate.notNull(obj);
31+
return JSON.toJSONString(obj).getBytes(StandardCharsets.UTF_8);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.json;
19+
20+
import org.junit.Test;
21+
22+
import static org.junit.Assert.assertEquals;
23+
24+
public class RocketMQJsonSerializerTest {
25+
@Test
26+
public void testSerializeAndDeserialize() throws Exception {
27+
RocketMQJsonSerializer<User> jsonSerializer = new RocketMQJsonSerializer<>();
28+
User user = new User();
29+
user.setName("tom");
30+
user.setAge(16);
31+
byte[] result = jsonSerializer.serialize(user);
32+
33+
RocketMQJsonDeserializer<User> jsonDeserializer = new RocketMQJsonDeserializer<>(User.class);
34+
assertEquals(user, jsonDeserializer.deserialize(result));
35+
}
36+
37+
}
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.rocketmq.serializer.json;
19+
20+
public class User {
21+
private String name;
22+
private int age;
23+
24+
public String getName() {
25+
return name;
26+
}
27+
28+
public void setName(String name) {
29+
this.name = name;
30+
}
31+
32+
public int getAge() {
33+
return age;
34+
}
35+
36+
public void setAge(int age) {
37+
this.age = age;
38+
}
39+
40+
@Override
41+
public boolean equals(Object obj) {
42+
if (obj == this) {
43+
return true;
44+
}
45+
if (obj instanceof User) {
46+
User u = (User)obj;
47+
if (u.name.equals(this.name) && u.age == this.age) {
48+
return true;
49+
}
50+
return false;
51+
}
52+
return false;
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!--
2+
~ Licensed to the Apache Software Foundation (ASF) under one or more
3+
~ contributor license agreements. See the NOTICE file distributed with
4+
~ this work for additional information regarding copyright ownership.
5+
~ The ASF licenses this file to You under the Apache License, Version 2.0
6+
~ (the "License"); you may not use this file except in compliance with
7+
~ the License. You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<component name="CopyrightManager">
19+
<copyright>
20+
<option name="myName" value="Apache"/>
21+
<option name="notice"
22+
value="Licensed to the Apache Software Foundation (ASF) under one or more&#10;contributor license agreements. See the NOTICE file distributed with&#10;this work for additional information regarding copyright ownership.&#10;The ASF licenses this file to You under the Apache License, Version 2.0&#10;(the &quot;License&quot;); you may not use this file except in compliance with&#10;the License. You may obtain a copy of the License at&#10;&#10; http://www.apache.org/licenses/LICENSE-2.0&#10;&#10;Unless required by applicable law or agreed to in writing, software&#10;distributed under the License is distributed on an &quot;AS IS&quot; BASIS,&#10;WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&#10;See the License for the specific language governing permissions and&#10;limitations under the License."/>
23+
</copyright>
24+
</component>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!--
2+
~ Licensed to the Apache Software Foundation (ASF) under one or more
3+
~ contributor license agreements. See the NOTICE file distributed with
4+
~ this work for additional information regarding copyright ownership.
5+
~ The ASF licenses this file to You under the Apache License, Version 2.0
6+
~ (the "License"); you may not use this file except in compliance with
7+
~ the License. You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<component name="CopyrightManager">
19+
<settings default="Apache">
20+
<module2copyright>
21+
<element module="All" copyright="Apache"/>
22+
</module2copyright>
23+
<LanguageOptions name="GSP">
24+
<option name="fileTypeOverride" value="3"/>
25+
<option name="prefixLines" value="false"/>
26+
</LanguageOptions>
27+
<LanguageOptions name="HTML">
28+
<option name="fileTypeOverride" value="3"/>
29+
<option name="prefixLines" value="false"/>
30+
</LanguageOptions>
31+
<LanguageOptions name="JAVA">
32+
<option name="fileTypeOverride" value="3"/>
33+
<option name="addBlankAfter" value="false"/>
34+
</LanguageOptions>
35+
<LanguageOptions name="JSP">
36+
<option name="fileTypeOverride" value="3"/>
37+
<option name="prefixLines" value="false"/>
38+
</LanguageOptions>
39+
<LanguageOptions name="JSPX">
40+
<option name="fileTypeOverride" value="3"/>
41+
<option name="prefixLines" value="false"/>
42+
</LanguageOptions>
43+
<LanguageOptions name="MXML">
44+
<option name="fileTypeOverride" value="3"/>
45+
<option name="prefixLines" value="false"/>
46+
</LanguageOptions>
47+
<LanguageOptions name="Properties">
48+
<option name="fileTypeOverride" value="3"/>
49+
<option name="block" value="false"/>
50+
</LanguageOptions>
51+
<LanguageOptions name="SPI">
52+
<option name="fileTypeOverride" value="3"/>
53+
<option name="block" value="false"/>
54+
</LanguageOptions>
55+
<LanguageOptions name="XML">
56+
<option name="fileTypeOverride" value="3"/>
57+
<option name="prefixLines" value="false"/>
58+
</LanguageOptions>
59+
<LanguageOptions name="__TEMPLATE__">
60+
<option name="separateBefore" value="true"/>
61+
<option name="lenBefore" value="1"/>
62+
</LanguageOptions>
63+
</settings>
64+
</component>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<!DOCTYPE module PUBLIC
20+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
21+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
22+
<!--Refer http://checkstyle.sourceforge.net/reports/google-java-style.html#s2.2-file-encoding -->
23+
<module name="Checker">
24+
25+
<property name="localeLanguage" value="en"/>
26+
27+
<!--To configure the check to report on the first instance in each file-->
28+
<module name="FileTabCharacter"/>
29+
30+
<!-- header -->
31+
<module name="RegexpHeader">
32+
<property name="header" value="/\*\nLicensed to the Apache Software Foundation*"/>
33+
</module>
34+
35+
<module name="RegexpSingleline">
36+
<property name="format" value="System\.out\.println"/>
37+
<property name="message" value="Prohibit invoking System.out.println in source code !"/>
38+
</module>
39+
40+
<module name="RegexpSingleline">
41+
<property name="format" value="//FIXME"/>
42+
<property name="message" value="Recommended fix FIXME task !"/>
43+
</module>
44+
45+
<module name="RegexpSingleline">
46+
<property name="format" value="//TODO"/>
47+
<property name="message" value="Recommended fix TODO task !"/>
48+
</module>
49+
50+
<module name="RegexpSingleline">
51+
<property name="format" value="@alibaba"/>
52+
<property name="message" value="Recommended remove @alibaba keyword!"/>
53+
</module>
54+
<module name="RegexpSingleline">
55+
<property name="format" value="@taobao"/>
56+
<property name="message" value="Recommended remove @taobao keyword!"/>
57+
</module>
58+
<module name="RegexpSingleline">
59+
<property name="format" value="@author"/>
60+
<property name="message" value="Recommended remove @author tag in javadoc!"/>
61+
</module>
62+
63+
<module name="RegexpSingleline">
64+
<property name="format"
65+
value=".*[\u3400-\u4DB5\u4E00-\u9FA5\u9FA6-\u9FBB\uF900-\uFA2D\uFA30-\uFA6A\uFA70-\uFAD9\uFF00-\uFFEF\u2E80-\u2EFF\u3000-\u303F\u31C0-\u31EF]+.*"/>
66+
<property name="message" value="Not allow chinese character !"/>
67+
</module>
68+
69+
<module name="FileLength">
70+
<property name="max" value="3000"/>
71+
</module>
72+
73+
<module name="TreeWalker">
74+
75+
<module name="UnusedImports">
76+
<property name="processJavadoc" value="true"/>
77+
</module>
78+
<module name="RedundantImport"/>
79+
80+
<!--<module name="IllegalImport" />-->
81+
82+
<!--Checks that classes that override equals() also override hashCode()-->
83+
<module name="EqualsHashCode"/>
84+
<!--Checks for over-complicated boolean expressions. Currently finds code like if (topic == true), topic || true, !false, etc.-->
85+
<module name="SimplifyBooleanExpression"/>
86+
<module name="OneStatementPerLine"/>
87+
<module name="UnnecessaryParentheses"/>
88+
<!--Checks for over-complicated boolean return statements. For example the following code-->
89+
<module name="SimplifyBooleanReturn"/>
90+
91+
<!--Check that the default is after all the cases in producerGroup switch statement-->
92+
<module name="DefaultComesLast"/>
93+
<!--Detects empty statements (standalone ";" semicolon)-->
94+
<module name="EmptyStatement"/>
95+
<!--Checks that long constants are defined with an upper ell-->
96+
<module name="UpperEll"/>
97+
<module name="ConstantName">
98+
<property name="format" value="(^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$)|(^log$)"/>
99+
</module>
100+
<!--Checks that local, non-final variable names conform to producerGroup format specified by the format property-->
101+
<module name="LocalVariableName"/>
102+
<!--Validates identifiers for local, final variables, including catch parameters-->
103+
<module name="LocalFinalVariableName"/>
104+
<!--Validates identifiers for non-static fields-->
105+
<module name="MemberName"/>
106+
<!--Validates identifiers for class type parameters-->
107+
<module name="ClassTypeParameterName">
108+
<property name="format" value="^[A-Z0-9]*$"/>
109+
</module>
110+
<!--Validates identifiers for method type parameters-->
111+
<module name="MethodTypeParameterName">
112+
<property name="format" value="^[A-Z0-9]*$"/>
113+
</module>
114+
<module name="PackageName"/>
115+
<module name="ParameterName"/>
116+
<module name="StaticVariableName"/>
117+
<module name="TypeName"/>
118+
<!--Checks that there are no import statements that use the * notation-->
119+
<module name="AvoidStarImport"/>
120+
121+
<!--whitespace-->
122+
<module name="GenericWhitespace"/>
123+
<module name="NoWhitespaceBefore"/>
124+
<module name="WhitespaceAfter"/>
125+
<module name="NoWhitespaceAfter"/>
126+
<module name="WhitespaceAround">
127+
<property name="allowEmptyConstructors" value="true"/>
128+
<property name="allowEmptyMethods" value="true"/>
129+
</module>
130+
<module name="Indentation"/>
131+
<module name="MethodParamPad"/>
132+
<module name="ParenPad"/>
133+
<module name="TypecastParenPad"/>
134+
</module>
135+
</module>
+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<!--
2+
~ Licensed to the Apache Software Foundation (ASF) under one or more
3+
~ contributor license agreements. See the NOTICE file distributed with
4+
~ this work for additional information regarding copyright ownership.
5+
~ The ASF licenses this file to You under the Apache License, Version 2.0
6+
~ (the "License"); you may not use this file except in compliance with
7+
~ the License. You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<code_scheme name="rocketmq">
19+
<option name="USE_SAME_INDENTS" value="true"/>
20+
<option name="IGNORE_SAME_INDENTS_FOR_LANGUAGES" value="true"/>
21+
<option name="OTHER_INDENT_OPTIONS">
22+
<value>
23+
<option name="INDENT_SIZE" value="4"/>
24+
<option name="CONTINUATION_INDENT_SIZE" value="4"/>
25+
<option name="TAB_SIZE" value="4"/>
26+
<option name="USE_TAB_CHARACTER" value="false"/>
27+
<option name="SMART_TABS" value="false"/>
28+
<option name="LABEL_INDENT_SIZE" value="0"/>
29+
<option name="LABEL_INDENT_ABSOLUTE" value="false"/>
30+
<option name="USE_RELATIVE_INDENTS" value="false"/>
31+
</value>
32+
</option>
33+
<option name="PREFER_LONGER_NAMES" value="false"/>
34+
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="1000"/>
35+
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="1000"/>
36+
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
37+
<value/>
38+
</option>
39+
<option name="IMPORT_LAYOUT_TABLE">
40+
<value>
41+
<package name="" withSubpackages="true" static="false"/>
42+
<emptyLine/>
43+
<package name="" withSubpackages="true" static="true"/>
44+
</value>
45+
</option>
46+
<option name="JD_ALIGN_PARAM_COMMENTS" value="false"/>
47+
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false"/>
48+
<option name="JD_P_AT_EMPTY_LINES" value="false"/>
49+
<option name="JD_KEEP_INVALID_TAGS" value="false"/>
50+
<option name="JD_DO_NOT_WRAP_ONE_LINE_COMMENTS" value="true"/>
51+
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false"/>
52+
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1"/>
53+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1"/>
54+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1"/>
55+
<option name="ELSE_ON_NEW_LINE" value="true"/>
56+
<option name="WHILE_ON_NEW_LINE" value="true"/>
57+
<option name="CATCH_ON_NEW_LINE" value="true"/>
58+
<option name="FINALLY_ON_NEW_LINE" value="true"/>
59+
<option name="ALIGN_MULTILINE_PARAMETERS" value="false"/>
60+
<option name="ALIGN_MULTILINE_FOR" value="false"/>
61+
<option name="SPACE_AFTER_TYPE_CAST" value="false"/>
62+
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true"/>
63+
<option name="METHOD_PARAMETERS_WRAP" value="1"/>
64+
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true"/>
65+
<option name="LABELED_STATEMENT_WRAP" value="1"/>
66+
<option name="WRAP_COMMENTS" value="true"/>
67+
<option name="METHOD_ANNOTATION_WRAP" value="1"/>
68+
<option name="CLASS_ANNOTATION_WRAP" value="1"/>
69+
<option name="FIELD_ANNOTATION_WRAP" value="1"/>
70+
<JavaCodeStyleSettings>
71+
<option name="CLASS_NAMES_IN_JAVADOC" value="3"/>
72+
</JavaCodeStyleSettings>
73+
<XML>
74+
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true"/>
75+
</XML>
76+
<ADDITIONAL_INDENT_OPTIONS fileType="haml">
77+
<option name="INDENT_SIZE" value="2"/>
78+
</ADDITIONAL_INDENT_OPTIONS>
79+
<codeStyleSettings language="Groovy">
80+
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false"/>
81+
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1"/>
82+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1"/>
83+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1"/>
84+
<option name="ELSE_ON_NEW_LINE" value="true"/>
85+
<option name="CATCH_ON_NEW_LINE" value="true"/>
86+
<option name="FINALLY_ON_NEW_LINE" value="true"/>
87+
<option name="ALIGN_MULTILINE_PARAMETERS" value="false"/>
88+
<option name="ALIGN_MULTILINE_FOR" value="false"/>
89+
<option name="SPACE_AFTER_TYPE_CAST" value="false"/>
90+
<option name="METHOD_PARAMETERS_WRAP" value="1"/>
91+
<option name="METHOD_ANNOTATION_WRAP" value="1"/>
92+
<option name="CLASS_ANNOTATION_WRAP" value="1"/>
93+
<option name="FIELD_ANNOTATION_WRAP" value="1"/>
94+
<option name="PARENT_SETTINGS_INSTALLED" value="true"/>
95+
<indentOptions>
96+
<option name="CONTINUATION_INDENT_SIZE" value="4"/>
97+
</indentOptions>
98+
</codeStyleSettings>
99+
<codeStyleSettings language="HOCON">
100+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1"/>
101+
<option name="PARENT_SETTINGS_INSTALLED" value="true"/>
102+
</codeStyleSettings>
103+
<codeStyleSettings language="JAVA">
104+
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false"/>
105+
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1"/>
106+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1"/>
107+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1"/>
108+
<option name="ELSE_ON_NEW_LINE" value="true"/>
109+
<option name="WHILE_ON_NEW_LINE" value="true"/>
110+
<option name="CATCH_ON_NEW_LINE" value="true"/>
111+
<option name="FINALLY_ON_NEW_LINE" value="true"/>
112+
<option name="ALIGN_MULTILINE_PARAMETERS" value="false"/>
113+
<option name="ALIGN_MULTILINE_FOR" value="false"/>
114+
<option name="SPACE_AFTER_TYPE_CAST" value="false"/>
115+
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true"/>
116+
<option name="METHOD_PARAMETERS_WRAP" value="1"/>
117+
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true"/>
118+
<option name="LABELED_STATEMENT_WRAP" value="1"/>
119+
<option name="METHOD_ANNOTATION_WRAP" value="1"/>
120+
<option name="CLASS_ANNOTATION_WRAP" value="1"/>
121+
<option name="FIELD_ANNOTATION_WRAP" value="1"/>
122+
<option name="PARENT_SETTINGS_INSTALLED" value="true"/>
123+
<indentOptions>
124+
<option name="CONTINUATION_INDENT_SIZE" value="4"/>
125+
</indentOptions>
126+
</codeStyleSettings>
127+
<codeStyleSettings language="JSON">
128+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1"/>
129+
<option name="PARENT_SETTINGS_INSTALLED" value="true"/>
130+
</codeStyleSettings>
131+
<codeStyleSettings language="Scala">
132+
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1"/>
133+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1"/>
134+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1"/>
135+
<option name="ELSE_ON_NEW_LINE" value="true"/>
136+
<option name="WHILE_ON_NEW_LINE" value="true"/>
137+
<option name="CATCH_ON_NEW_LINE" value="true"/>
138+
<option name="FINALLY_ON_NEW_LINE" value="true"/>
139+
<option name="ALIGN_MULTILINE_PARAMETERS" value="false"/>
140+
<option name="ALIGN_MULTILINE_FOR" value="false"/>
141+
<option name="METHOD_PARAMETERS_WRAP" value="1"/>
142+
<option name="METHOD_ANNOTATION_WRAP" value="1"/>
143+
<option name="CLASS_ANNOTATION_WRAP" value="1"/>
144+
<option name="FIELD_ANNOTATION_WRAP" value="1"/>
145+
<option name="PARENT_SETTINGS_INSTALLED" value="true"/>
146+
<indentOptions>
147+
<option name="INDENT_SIZE" value="4"/>
148+
<option name="CONTINUATION_INDENT_SIZE" value="4"/>
149+
<option name="TAB_SIZE" value="4"/>
150+
</indentOptions>
151+
</codeStyleSettings>
152+
<codeStyleSettings language="XML">
153+
<indentOptions>
154+
<option name="CONTINUATION_INDENT_SIZE" value="4"/>
155+
</indentOptions>
156+
</codeStyleSettings>
157+
</code_scheme>

0 commit comments

Comments
 (0)
Please sign in to comment.