Skip to content

Commit

Permalink
#25 update global API
Browse files Browse the repository at this point in the history
  • Loading branch information
Siarhei_Kakichau committed Jul 5, 2024
1 parent 9ce653a commit f6e4754
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions messaging-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ repositories {
}

dependencies {

implementation 'org.apache.kafka:kafka-clients:3.4.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'

testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
}
Expand Down
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;
}
}
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;
}
}
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
}
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);
}
}
}
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);
}
}
}

0 comments on commit f6e4754

Please sign in to comment.