-
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
Siarhei_Kakichau
committed
Jul 5, 2024
1 parent
9ce653a
commit f6e4754
Showing
6 changed files
with
92 additions
and
0 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
26 changes: 26 additions & 0 deletions
26
messaging-api/src/main/java/org/student/messaging/models/BaseArtifactMessage.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,26 @@ | ||
package org.student.messaging.models; | ||
|
||
import java.util.UUID; | ||
|
||
public class BaseArtifactMessage { | ||
|
||
private UUID internalId; | ||
|
||
private ResponseCode responseCode; | ||
|
||
public UUID getInternalId() { | ||
return internalId; | ||
} | ||
|
||
public void setInternalId(UUID internalId) { | ||
this.internalId = internalId; | ||
} | ||
|
||
public ResponseCode getResponseCode() { | ||
return responseCode; | ||
} | ||
|
||
public void setResponseCode(ResponseCode responseCode) { | ||
this.responseCode = responseCode; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
messaging-api/src/main/java/org/student/messaging/models/BodyArtifactMessage.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,14 @@ | ||
package org.student.messaging.models; | ||
|
||
public class BodyArtifactMessage extends BaseArtifactMessage{ | ||
|
||
private byte[] artifactBody; | ||
|
||
public byte[] getArtifactBody() { | ||
return artifactBody; | ||
} | ||
|
||
public void setArtifactBody(byte[] artifactBody) { | ||
this.artifactBody = artifactBody; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
messaging-api/src/main/java/org/student/messaging/models/ResponseCode.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,5 @@ | ||
package org.student.messaging.models; | ||
|
||
public enum ResponseCode { | ||
CREATED, READED, DELETED, FAILED | ||
} |
26 changes: 26 additions & 0 deletions
26
messaging-api/src/main/java/org/student/messaging/models/serializers/JsonDeserializer.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,26 @@ | ||
package org.student.messaging.models.serializers; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.kafka.common.errors.SerializationException; | ||
import org.apache.kafka.common.serialization.Deserializer; | ||
|
||
import java.util.Map; | ||
|
||
public class JsonDeserializer<T> implements Deserializer<T> { | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
private Class<T> type; | ||
|
||
@Override | ||
public void configure(Map<String, ?> configs, boolean isKey) { | ||
this.type = (Class<T>) configs.get("value.deserializer.type"); | ||
} | ||
|
||
@Override | ||
public T deserialize(String topic, byte[] data) { | ||
try { | ||
return objectMapper.readValue(data, type); | ||
} catch (Exception e) { | ||
throw new SerializationException("Error deserializing value", e); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
messaging-api/src/main/java/org/student/messaging/models/serializers/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,17 @@ | ||
package org.student.messaging.models.serializers; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.kafka.common.errors.SerializationException; | ||
import org.apache.kafka.common.serialization.Serializer; | ||
|
||
public class JsonSerializer<T> implements Serializer<T> { | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
@Override | ||
public byte[] serialize(String s, T baseArtifactMessage) { | ||
try { | ||
return objectMapper.writeValueAsBytes(baseArtifactMessage); | ||
} catch (Exception e) { | ||
throw new SerializationException("Error serializing value", e); | ||
} | ||
} | ||
} |