Skip to content

Commit 3be9ff8

Browse files
vishnu-alapatiVishnu Alapati
andauthored
Implement log level changes and improvements for REMReM and Translator (#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>
1 parent 7ade041 commit 3be9ff8

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
## 2.1.1
2+
- Implemented the changes to log the eventId and HTTPStatus while the level is INFO.
3+
14
## 2.1.0
25
- Implemented new routing key template for Sepia.
3-
-
6+
47
## 2.0.30
58
- Upgrading to OpenJDK 17
69

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<version>2.0.12</version>
1010
</parent>
1111
<properties>
12-
<eiffel-remrem-publish.version>2.1.0</eiffel-remrem-publish.version>
12+
<eiffel-remrem-publish.version>2.1.1</eiffel-remrem-publish.version>
1313
<eiffel-remrem-semantics.version>2.3.0</eiffel-remrem-semantics.version>
1414
</properties>
1515
<artifactId>eiffel-remrem-publish</artifactId>

publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/helper/RMQHelper.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
import com.ericsson.eiffel.remrem.publish.config.RabbitMqPropertiesConfig;
3333
import com.ericsson.eiffel.remrem.publish.exception.NackException;
3434
import com.ericsson.eiffel.remrem.publish.exception.RemRemPublishException;
35+
import com.google.gson.Gson;
36+
import com.google.gson.GsonBuilder;
37+
import com.google.gson.JsonObject;
38+
import com.google.gson.JsonParser;
3539

3640
import ch.qos.logback.classic.Level;
3741
import ch.qos.logback.classic.Logger;
@@ -40,6 +44,7 @@
4044

4145
private static final String FALSE = "false";
4246

47+
private static Gson gson;
4348
@Autowired
4449
RabbitMqPropertiesConfig rabbitMqPropertiesConfig;
4550

@@ -66,6 +71,17 @@ public void init() throws RemRemPublishException {
6671
}
6772
}
6873

74+
/**
75+
* This method is used to give the Gson object
76+
* @return Gson
77+
*/
78+
public static Gson getGson() {
79+
if (gson == null) {
80+
gson = new GsonBuilder().create();
81+
}
82+
return gson;
83+
}
84+
6985
/**
7086
* This method is used to set protocol specific RabbitMQ properties
7187
* @param protocol name
@@ -91,9 +107,10 @@ private void protocolInit(String protocol) throws RemRemPublishException {
91107

92108
public void send(String routingKey, String msg, MsgService msgService) throws IOException, NackException, TimeoutException, RemRemPublishException, IllegalArgumentException {
93109
String protocol = msgService.getServiceName();
110+
String eventId = msgService.getEventId(getGson().fromJson(msg, JsonObject.class));
94111
RabbitMqProperties rabbitmqProtocolProperties = rabbitMqPropertiesMap.get(protocol);
95112
if (rabbitmqProtocolProperties != null) {
96-
rabbitmqProtocolProperties.send(routingKey, msg);
113+
rabbitmqProtocolProperties.send(routingKey, msg, eventId);
97114
} else {
98115
log.error("RabbitMq properties not configured for the protocol " + protocol);
99116
}

publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/helper/RabbitMqProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ private boolean hasExchange() throws RemRemPublishException {
513513
* @throws TimeoutException
514514
* @throws RemRemPublishException
515515
*/
516-
public void send(String routingKey, String msg)
516+
public void send(String routingKey, String msg, String eventId)
517517
throws IOException, NackException, TimeoutException, RemRemPublishException, IllegalArgumentException {
518518
Channel channel = giveMeRandomChannel();
519519
checkAndCreateExchangeIfNeeded();
@@ -537,7 +537,7 @@ public void shutdownCompleted(ShutdownSignalException cause) {
537537

538538
try {
539539
channel.basicPublish(exchangeName, routingKey, msgProps, msg.getBytes());
540-
log.info("Published message with size {} bytes on exchange '{}' with routing key '{}'",
540+
log.info("Published message {} with size {} bytes on exchange '{}' with routing key '{}'", eventId,
541541
msg.getBytes().length, exchangeName, routingKey);
542542
if (waitForConfirmsTimeOut == null || waitForConfirmsTimeOut == 0) {
543543
waitForConfirmsTimeOut = DEFAULT_WAIT_FOR_CONFIRMS_TIMEOUT;

publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public ResponseEntity send(@ApiParam(value = "message protocol", required = true
113113
}
114114
} synchronized(this) {
115115
SendResult result = messageService.send(body, msgService, userDomain, tag, routingKey);
116+
log.info("HTTP Status: {}", messageService.getHttpStatus().value());
116117
return new ResponseEntity(result, messageService.getHttpStatus());
117118
}
118119
}

publish-service/src/test/java/com/ericsson/eiffel/remrem/publish/service/MessageServiceRMQImplUnitTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ public void testCreateExchangeIfNotExistingDisable() throws RemRemPublishExcepti
120120
}
121121

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

129128
@Test public void testSingleSuccessfulEvent() throws Exception {
@@ -193,12 +192,13 @@ public void testCreateExchangeIfNotExistingDisable() throws RemRemPublishExcepti
193192
}
194193

195194
@Test
196-
public void testRabbitMQConnection() throws NackException, TimeoutException, RemRemPublishException {
195+
public void testRabbitMQConnection() throws TimeoutException, RemRemPublishException, IOException {
196+
String body = FileUtils.readFileToString(new File("src/test/resources/EiffelActivityFinishedEvent.json"));
197197
try {
198198
if(rabbitmqProtocolProperties != null) {
199199
rabbitmqProtocolProperties.createRabbitMqConnection();
200200
MsgService msgService = PublishUtils.getMessageService(protocol, msgServices);
201-
rmqHelper.send("eiffelxxx", "Test message", msgService);
201+
rmqHelper.send("eiffelxxx", body, msgService);
202202
assertTrue(rabbitmqProtocolProperties.getRabbitConnection().isOpen());
203203
}
204204
} catch (IOException e) {

0 commit comments

Comments
 (0)