Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to override deserializer in Kafka consumer
- When binding the consumer, the kafka consumer should not be set to use `ByteArrayDeserializer` for both key/value deserializer. Instead, they need to be used as the default values. Any extended consumer properties for key/value deserializer should override this default deserializer. - Add test This resolves #55 Add tests for custom/native serialization - Test using built-in serialization without using kafka native serialization (ie. both the serializer/de-serializer are set to use ByteArraySe/Deserializer) - Test using custom serializer by explicitly setting value.deserializer for both Kafka producer/consumer properties - Test avro message conversion and Kafka Avro Serializer using Confluent Schema Registry - Given pre-released registry versions have some bugs that blocks the testing and `3.0.1` requires Kafka 0.10, this test is only in Kafka .10 binder Update Schema based custom serializer/de-serializer tests Fix import Handle unbind during tests appropriately
- Loading branch information
1 parent
943a7ae
commit 36c90aa
Showing
7 changed files
with
367 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ _site/ | |
*.ipr | ||
*.iws | ||
.idea/* | ||
*/.idea | ||
.factorypath | ||
dump.rdb | ||
.apt_generated | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...er-kafka-0.10-test/src/test/java/org/springframework/cloud/stream/binder/kafka/User1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2016 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.cloud.stream.binder.kafka; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.avro.Schema; | ||
import org.apache.avro.reflect.Nullable; | ||
import org.apache.avro.specific.SpecificRecordBase; | ||
|
||
import org.springframework.core.io.ClassPathResource; | ||
|
||
/** | ||
* @author Marius Bogoevici | ||
* @author Ilayaperumal Gopinathan | ||
*/ | ||
public class User1 extends SpecificRecordBase { | ||
|
||
@Nullable | ||
private String name; | ||
|
||
@Nullable | ||
private String favoriteColor; | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getFavoriteColor() { | ||
return this.favoriteColor; | ||
} | ||
|
||
public void setFavoriteColor(String favoriteColor) { | ||
this.favoriteColor = favoriteColor; | ||
} | ||
|
||
@Override | ||
public Schema getSchema() { | ||
try { | ||
return new Schema.Parser().parse(new ClassPathResource("schemas/users_v1.schema").getInputStream()); | ||
} | ||
catch (IOException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public Object get(int i) { | ||
if (i == 0) { | ||
return getName().toString(); | ||
} | ||
if (i == 1) { | ||
return getFavoriteColor().toString(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void put(int i, Object o) { | ||
if (i == 0) { | ||
setName((String) o); | ||
} | ||
if (i == 1) { | ||
setFavoriteColor((String) o); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
spring-cloud-stream-binder-kafka-0.10-test/src/test/resources/schemas/users_v1.schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{"namespace": "org.springframework.cloud.stream.binder.kafka", | ||
"type": "record", | ||
"name": "User1", | ||
"fields": [ | ||
{"name": "name", "type": "string"}, | ||
{"name": "favoriteColor", "type": "string"} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.