forked from crossoverJie/SSM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bb52be
commit cbfae5d
Showing
4 changed files
with
105 additions
and
8 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
44 changes: 44 additions & 0 deletions
44
...ORDER-CONSUMER/src/main/java/com/crossoverjie/kafka/orderconsumer/dto/JsonSerializer.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,44 @@ | ||
package com.crossoverjie.kafka.orderconsumer.dto; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
import org.apache.kafka.common.errors.SerializationException; | ||
import org.apache.kafka.common.serialization.Serializer; | ||
|
||
import java.util.Map; | ||
|
||
|
||
public class JsonSerializer<T> implements Serializer<T> { | ||
|
||
public JsonSerializer() { | ||
|
||
} | ||
|
||
|
||
@Override | ||
public void configure(Map<String, ?> configs, boolean isKey) { | ||
// No-op | ||
} | ||
|
||
@Override | ||
public byte[] serialize(String topic, T data) { | ||
try { | ||
byte[] result = null; | ||
if (data != null) { | ||
|
||
result = JSONObject.toJSONBytes(data, | ||
SerializerFeature.UseISO8601DateFormat, | ||
SerializerFeature.WriteMapNullValue, | ||
SerializerFeature.WriteClassName); | ||
} | ||
return result; | ||
} catch (Exception ex) { | ||
throw new SerializationException("Can't serialize data [" + data + "] for topic [" + topic + "]", ex); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// No-op | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...NDS-KILL-ORDER-CONSUMER/src/main/java/com/crossoverjie/kafka/orderconsumer/dto/Stock.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,59 @@ | ||
package com.crossoverjie.kafka.orderconsumer.dto; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* @author crossoverJie | ||
*/ | ||
public class Stock implements Serializable{ | ||
private static final long serialVersionUID = -8437012513227627973L; | ||
private Integer id; | ||
|
||
private String name; | ||
|
||
private Integer count; | ||
|
||
private Integer sale; | ||
|
||
private Integer version; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Integer getCount() { | ||
return count; | ||
} | ||
|
||
public void setCount(Integer count) { | ||
this.count = count; | ||
} | ||
|
||
public Integer getSale() { | ||
return sale; | ||
} | ||
|
||
public void setSale(Integer sale) { | ||
this.sale = sale; | ||
} | ||
|
||
public Integer getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(Integer version) { | ||
this.version = version; | ||
} | ||
} |
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