Skip to content

Commit

Permalink
Implement log level changes and improvements for REMReM and Translator (
Browse files Browse the repository at this point in the history
#275)

* Made changes to print eventID and status code while the log level is info

---------

Co-authored-by: Vishnu Alapati <zalavis@seliiuts03320.seli.gic.ericsson.se>
  • Loading branch information
vishnu-alapati and Vishnu Alapati authored Aug 28, 2023
1 parent 7ade041 commit 3be9ff8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## 2.1.1
- Implemented the changes to log the eventId and HTTPStatus while the level is INFO.

## 2.1.0
- Implemented new routing key template for Sepia.
-

## 2.0.30
- Upgrading to OpenJDK 17

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>2.0.12</version>
</parent>
<properties>
<eiffel-remrem-publish.version>2.1.0</eiffel-remrem-publish.version>
<eiffel-remrem-publish.version>2.1.1</eiffel-remrem-publish.version>
<eiffel-remrem-semantics.version>2.3.0</eiffel-remrem-semantics.version>
</properties>
<artifactId>eiffel-remrem-publish</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
import com.ericsson.eiffel.remrem.publish.config.RabbitMqPropertiesConfig;
import com.ericsson.eiffel.remrem.publish.exception.NackException;
import com.ericsson.eiffel.remrem.publish.exception.RemRemPublishException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
Expand All @@ -40,6 +44,7 @@

private static final String FALSE = "false";

private static Gson gson;
@Autowired
RabbitMqPropertiesConfig rabbitMqPropertiesConfig;

Expand All @@ -66,6 +71,17 @@ public void init() throws RemRemPublishException {
}
}

/**
* This method is used to give the Gson object
* @return Gson
*/
public static Gson getGson() {
if (gson == null) {
gson = new GsonBuilder().create();
}
return gson;
}

/**
* This method is used to set protocol specific RabbitMQ properties
* @param protocol name
Expand All @@ -91,9 +107,10 @@ private void protocolInit(String protocol) throws RemRemPublishException {

public void send(String routingKey, String msg, MsgService msgService) throws IOException, NackException, TimeoutException, RemRemPublishException, IllegalArgumentException {
String protocol = msgService.getServiceName();
String eventId = msgService.getEventId(getGson().fromJson(msg, JsonObject.class));
RabbitMqProperties rabbitmqProtocolProperties = rabbitMqPropertiesMap.get(protocol);
if (rabbitmqProtocolProperties != null) {
rabbitmqProtocolProperties.send(routingKey, msg);
rabbitmqProtocolProperties.send(routingKey, msg, eventId);
} else {
log.error("RabbitMq properties not configured for the protocol " + protocol);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ private boolean hasExchange() throws RemRemPublishException {
* @throws TimeoutException
* @throws RemRemPublishException
*/
public void send(String routingKey, String msg)
public void send(String routingKey, String msg, String eventId)
throws IOException, NackException, TimeoutException, RemRemPublishException, IllegalArgumentException {
Channel channel = giveMeRandomChannel();
checkAndCreateExchangeIfNeeded();
Expand All @@ -537,7 +537,7 @@ public void shutdownCompleted(ShutdownSignalException cause) {

try {
channel.basicPublish(exchangeName, routingKey, msgProps, msg.getBytes());
log.info("Published message with size {} bytes on exchange '{}' with routing key '{}'",
log.info("Published message {} with size {} bytes on exchange '{}' with routing key '{}'", eventId,
msg.getBytes().length, exchangeName, routingKey);
if (waitForConfirmsTimeOut == null || waitForConfirmsTimeOut == 0) {
waitForConfirmsTimeOut = DEFAULT_WAIT_FOR_CONFIRMS_TIMEOUT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public ResponseEntity send(@ApiParam(value = "message protocol", required = true
}
} synchronized(this) {
SendResult result = messageService.send(body, msgService, userDomain, tag, routingKey);
log.info("HTTP Status: {}", messageService.getHttpStatus().value());
return new ResponseEntity(result, messageService.getHttpStatus());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ public void testCreateExchangeIfNotExistingDisable() throws RemRemPublishExcepti
}

@Test public void sendNormal() throws Exception {
Map<String, String> map = new HashMap<String, String>();
String body = FileUtils.readFileToString(new File("src/test/resources/EiffelActivityFinishedEvent.json"));
MsgService msgService = PublishUtils.getMessageService(protocol, msgServices);
map.put("test", "test");
messageService.send(map, map, msgService);
rmqHelper.send("eiffelxxx", body, msgService);
}

@Test public void testSingleSuccessfulEvent() throws Exception {
Expand Down Expand Up @@ -193,12 +192,13 @@ public void testCreateExchangeIfNotExistingDisable() throws RemRemPublishExcepti
}

@Test
public void testRabbitMQConnection() throws NackException, TimeoutException, RemRemPublishException {
public void testRabbitMQConnection() throws TimeoutException, RemRemPublishException, IOException {
String body = FileUtils.readFileToString(new File("src/test/resources/EiffelActivityFinishedEvent.json"));
try {
if(rabbitmqProtocolProperties != null) {
rabbitmqProtocolProperties.createRabbitMqConnection();
MsgService msgService = PublishUtils.getMessageService(protocol, msgServices);
rmqHelper.send("eiffelxxx", "Test message", msgService);
rmqHelper.send("eiffelxxx", body, msgService);
assertTrue(rabbitmqProtocolProperties.getRabbitConnection().isOpen());
}
} catch (IOException e) {
Expand Down

0 comments on commit 3be9ff8

Please sign in to comment.