Skip to content

Commit 8d860e5

Browse files
vishnu-alapatiVishnu
andauthored
When we change the configurable timeout parameters it is taking default value only (#251)
* When we change the configurable timeout parameters it is taking default values instead of changed values. Co-authored-by: Vishnu <vishnu.alapati@ericsson.com>
1 parent 7c16916 commit 8d860e5

File tree

3 files changed

+99
-23
lines changed

3 files changed

+99
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 2.0.26
22
- Added code changes so that REMReM Publish should not die if RabbitMQ is unavailable when starting up.
3+
- Updated documentation and added code changes related to channels count and timeout parameters.
34

45
## 2.0.25
56
- Implemented "publisher confirms " in REMReM so that this can be used to get confirmation about the messages sent to MB.

publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/config/RabbitMqPropertiesConfig.java

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,43 @@ public class RabbitMqPropertiesConfig {
6161
private static final String GENERATE_SERVER_URI = "generate.server.uri";
6262
private static final String GENERATE_SERVER_PATH = "generate.server.contextpath";
6363

64+
private static final String PROPERTY_MP = "mp";
65+
private static final String PROPERTY_HOST = "host";
66+
private static final String PROPERTY_EXCHANGE_NAME = "exchangeName";
67+
private static final String PROPERTY_PORT = "port";
68+
private static final String PROPERTY_TLSVER = "tls";
69+
private static final String PROPERTY_VIRTUAL_HOST = "virtualHost";
70+
private static final String PROPERTY_USERNAME = "username";
71+
private static final String PROPERTY_PASSWORD = "password";
72+
private static final String PROPERTY_DOMAINID = "domainId";
73+
private static final String PROPERTY_CHANNELS_COUNT = "channelsCount";
74+
private static final String PROPERTY_CREATE_EXCHANGE_IF_NOTEXISTING = "createExchangeIfNotExisting";
75+
private static final String PROPERTY_TCP_TIMEOUT = "tcpTimeOut";
76+
private static final String PROPERTY_WAIT_FOR_CONFIRMS_TIMEOUT = "waitForConfirmsTimeOut";
77+
78+
/***
79+
* This method is used to get the RabbitMq property value.
80+
*
81+
* @return RabbitMq property or null if the property name was not found
82+
*/
83+
String getPropertyAsText(JsonNode node, String property) {
84+
JsonNode jsonNode = node.get(property);
85+
return jsonNode != null ? jsonNode.asText() : null;
86+
}
87+
88+
/***
89+
* This method is used to get the RabbitMq property value.
90+
*
91+
* @return RabbitMq property or null if the property name was not found
92+
*/
93+
Boolean getPropertyAsBoolean(JsonNode node, String property) {
94+
JsonNode jsonNode = node.get(property);
95+
return jsonNode != null ? jsonNode.asBoolean() : null;
96+
}
97+
6498
/***
6599
* This method is used to give RabbitMq properties based on protocol
66-
*
100+
*
67101
* @return protocol specific RabbitMq properties in map
68102
*/
69103
public Map<String, RabbitMqProperties> getRabbitMqProperties() {
@@ -92,41 +126,42 @@ private void readSpringProperties() {
92126

93127
for (int i = 0; i < rabbitmqInstancesJsonListJsonArray.size(); i++) {
94128
JsonNode rabbitmqInstanceObject = rabbitmqInstancesJsonListJsonArray.get(i);
95-
String protocol = rabbitmqInstanceObject.get("mp").asText();
129+
String protocol = getPropertyAsText(rabbitmqInstanceObject, PROPERTY_MP);
96130
log.info("Configuring RabbitMq instance for Eiffel message protocol: " + protocol);
97131

98132
RabbitMqProperties rabbitMqProperties = new RabbitMqProperties();
99-
rabbitMqProperties.setHost(rabbitmqInstanceObject.get("host").asText());
100-
rabbitMqProperties.setPort(Integer.parseInt(rabbitmqInstanceObject.get("port").asText()));
101-
if((rabbitmqInstanceObject.get("virtualHost") != null) ) {
102-
rabbitMqProperties.setVirtualHost(rabbitmqInstanceObject.get("virtualHost").asText());
133+
rabbitMqProperties.setHost(getPropertyAsText(rabbitmqInstanceObject, PROPERTY_HOST));
134+
rabbitMqProperties.setPort(Integer.parseInt(getPropertyAsText(rabbitmqInstanceObject, PROPERTY_PORT)));
135+
String virtualHost = getPropertyAsText(rabbitmqInstanceObject, PROPERTY_VIRTUAL_HOST);
136+
if(virtualHost != null) {
137+
rabbitMqProperties.setVirtualHost(virtualHost);
103138
}
104-
rabbitMqProperties.setUsername(rabbitmqInstanceObject.get("username").asText());
105-
String rabbitMqPassword = rabbitmqInstanceObject.get("password").asText();
139+
rabbitMqProperties.setUsername(getPropertyAsText(rabbitmqInstanceObject, PROPERTY_USERNAME));
140+
String rabbitMqPassword = getPropertyAsText(rabbitmqInstanceObject, PROPERTY_PASSWORD);
106141
if (rabbitMqPassword.startsWith("{ENC(") && rabbitMqPassword.endsWith("}")) {
107142
rabbitMqPassword = rabbitMqPassword.substring(1, rabbitMqPassword.length() - 1);
108143
rabbitMqProperties.setPassword(DecryptionUtils.decryptString(rabbitMqPassword, jasyptKey));
109144
}
110145
else{
111146
rabbitMqProperties.setPassword(rabbitMqPassword);
112147
}
113-
rabbitMqProperties.setTlsVer(rabbitmqInstanceObject.get("tls").asText());
114-
rabbitMqProperties.setExchangeName(rabbitmqInstanceObject.get("exchangeName").asText());
115-
rabbitMqProperties.setCreateExchangeIfNotExisting(rabbitmqInstanceObject.get("createExchangeIfNotExisting").asBoolean());
116-
rabbitMqProperties.setDomainId(rabbitmqInstanceObject.get("domainId").asText());
117-
if((rabbitmqInstanceObject.get("channelsCount") != null) ) {
148+
rabbitMqProperties.setTlsVer(getPropertyAsText(rabbitmqInstanceObject, PROPERTY_TLSVER));
149+
rabbitMqProperties.setExchangeName(getPropertyAsText(rabbitmqInstanceObject, PROPERTY_EXCHANGE_NAME));
150+
rabbitMqProperties.setCreateExchangeIfNotExisting(getPropertyAsBoolean(rabbitmqInstanceObject, PROPERTY_CREATE_EXCHANGE_IF_NOTEXISTING));
151+
rabbitMqProperties.setDomainId(getPropertyAsText(rabbitmqInstanceObject, PROPERTY_DOMAINID));
152+
String channelsCount = getPropertyAsText(rabbitmqInstanceObject, PROPERTY_CHANNELS_COUNT);
153+
if (channelsCount != null) {
118154
rabbitMqProperties.setChannelsCount(
119-
Integer.getInteger(rabbitmqInstanceObject.get("channelsCount").asText(),
120-
RabbitMqProperties.DEFAULT_CHANNEL_COUNT));
155+
Integer.parseInt(channelsCount));
121156
}
122-
if((rabbitmqInstanceObject.get("waitForConfirmsTimeOut") != null) ) {
123-
rabbitMqProperties.setWaitForConfirmsTimeOut(Long.getLong(
124-
rabbitmqInstanceObject.get("waitForConfirmsTimeOut").asText(),
125-
RabbitMqProperties.DEFAULT_WAIT_FOR_CONFIRMS_TIMEOUT));
157+
String waitForConfirmsTimeOut = getPropertyAsText(rabbitmqInstanceObject, PROPERTY_WAIT_FOR_CONFIRMS_TIMEOUT);
158+
if (waitForConfirmsTimeOut != null) {
159+
rabbitMqProperties.setWaitForConfirmsTimeOut(Long.parseLong(waitForConfirmsTimeOut));
126160
}
127-
if ((rabbitmqInstanceObject.get("tcpTimeOut") != null)) {
128-
rabbitMqProperties.setTcpTimeOut(Integer.getInteger(rabbitmqInstanceObject.get("tcpTimeOut").asText(),
129-
RabbitMqProperties.DEFAULT_TCP_TIMEOUT));
161+
String tcpTimeOut = getPropertyAsText(rabbitmqInstanceObject, PROPERTY_TCP_TIMEOUT);
162+
if (tcpTimeOut != null) {
163+
rabbitMqProperties.setTcpTimeOut(
164+
Integer.parseInt(tcpTimeOut));
130165
}
131166
rabbitMqPropertiesMap.put(protocol, rabbitMqProperties);
132167
}

wiki/markdown/statusCodes.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Below is the status codes:
1515
| 404 | RabbitMQ properties not found | RabbitMQ properties not configured for the protocol <protocol> | Is returned if RabbitMQ message broker properties are not found for the protocol used by event. |
1616
| 500 | Internal Server Error | RabbitMQ is down. Please try later | Is returned if RabbitMQ is down. |
1717
| | | Could not prepare Routing key to publish message. | Is returned if could not prepare routing key to publish the eiffel event. |
18-
| 503 | Service Unavailable | Please check previous event and try again later | Is returned if there is a failure in publishing previous event with status code 400, 404 or 500. |
18+
| 503 | Service Unavailable | Please check previous event and try again later | Is returned if there is a failure in publishing previous event with status code 400, 404 or 500.
19+
| 504 | Gateway Timeout | Time out waiting for ACK | Is returned if event is not confirmed within waitForConfirmsTimeout. |
1920

2021
### Status codes explanation
2122

@@ -114,6 +115,45 @@ Event is failed to send because of internal server error.
114115
}
115116
]
116117
```
118+
When previous Event is failed to send because of Gateway Timeout.
119+
120+
```
121+
[
122+
{
123+
"id": "9cdd0f68-df85-44b0-88bd-fc4163ac90a0",
124+
"status_code": 500,
125+
"result": "Internal Server Error",
126+
"message": "Channel was closed for Rabbitmq connection <hostaddress>"
127+
}
128+
]
129+
```
130+
131+
When message is nack-ed i.e broker could not take care of it for some reason.
132+
133+
```
134+
[
135+
{
136+
"id": "9cdd0f68-df85-44b0-88bd-fc4163ac90a0",
137+
"status_code": 500,
138+
"result": "Internal Server Error",
139+
"message": "Message is nacked"
140+
}
141+
]
142+
```
143+
144+
**504 Gateway Timeout**
145+
146+
Event is not confirmed by RabbitMq within specified waitForConfirmsTimeout.
147+
148+
```
149+
[
150+
{
151+
"status_code": 504,
152+
"result": "Gateway Timeout",
153+
"message": "Time out waiting for ACK"
154+
}
155+
]
156+
```
117157

118158
**503 Service Unavailable**
119159

0 commit comments

Comments
 (0)