Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding JMS Consumer/Publisher Client #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cbabey
Copy link

@cbabey cbabey commented Aug 29, 2023

Description

This pull request introduces a JMS Consumer/Publisher Client tool to address situations where JMS events might not be consumed correctly by the gateway, as indicated by the gateway listener debug logs. Even though the event publisher log adaptor is configured for the relevant stream, showing that the message was received in the event stream, it doesn't necessarily confirm the proper publication of the event to the broker through the JMSeventPublisher. This tool provides a solution by allowing manual verification of event publication and consumption, aiding in identifying any issues between the JMS publisher flow and the consumption flow.

Changes Made

  • Added a JMS Consumer/Publisher Client tool to the project.
  • Provided instructions for building and using the tool in the README.
  • updated the root readMe file by adding the link to JMS consumer publisher client

@dilshanfardil dilshanfardil self-requested a review March 29, 2024 14:53

import org.json.JSONObject;

import javax.jms.*;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we remove the wild card imports

* Read configurations from config.xml file.
*/
public class ReadConfigFile {
private Properties properties = new Properties();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this final

/**
* Read configurations from config.xml file.
*/
public class ReadConfigFile {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better if we change the name of the class since this is more like a method name. You can try a name like ConfigFileReader so something like that

public ReadConfigFile() {

// Load properties from external file if it exists
try {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we move this to try with resource ?

// Load default properties from JAR if not overridden externally
if (properties.isEmpty()) {
System.out.println("Reading internal config file");
try {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try with resource

}
} catch (JMSException e) {
System.out.print("Error While Reading The JMS Message " + e.getMessage());
} catch (JsonProcessingException e) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since both the catches has the same output and JsonProcessingException is no needed you can remove that

@Override
public void onMessage(Message message) {
try {
Topic jmsDestination = (Topic) message.getJMSDestination();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find any usage of this. You can remove this

System.out.println("-------- EVENT RECEIVED -------------");
System.out.println("EVENT RECEIVED :" + payloadData);
String event = payloadData.get("event").asText();
if (event != null && !event.isEmpty()){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is String you can use Strings.isNullOrEmpty(event)

if (message instanceof TextMessage) {
String textMessage = ((TextMessage) message).getText();
JsonNode payloadData = new ObjectMapper().readTree(textMessage).path("event").path("payloadData");
System.out.println("-------- EVENT RECEIVED -------------");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reformat the code

protected String password = "admin";
protected String topicName = "notification";

private void readProperties(){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we break the rule "Single Responsibility" JMSBase is a common class and we are using to create the Publisher and Reciver. They don't need to know how the properties are extracted, you can simply move this logic to the ReadConfgFile class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants