diff --git a/service/application/pom.xml b/service/application/pom.xml index b9fabafb..3e04a3f9 100644 --- a/service/application/pom.xml +++ b/service/application/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 com.solace.maas @@ -341,6 +342,17 @@ + + org.springframework.boot + spring-boot-maven-plugin + + + + build-info + + + + diff --git a/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java b/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java index 1e1a17a1..83a591f0 100644 --- a/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java +++ b/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java @@ -12,12 +12,13 @@ public class HeartbeatMessage extends MOPMessage { private String orgId; private String runtimeAgentId; private String timestamp; + private String runtimeAgentVersion; public HeartbeatMessage() { super(); } - public HeartbeatMessage(String runtimeAgentId, String timestamp) { + public HeartbeatMessage(String runtimeAgentId, String timestamp, String runtimeAgentVersion) { super(); withMessageType(MOPMessageType.generic) .withProtocol(MOPProtocol.EMAHeartbeat) @@ -25,6 +26,7 @@ public HeartbeatMessage(String runtimeAgentId, String timestamp) { .withUhFlag(MOPUHFlag.ignore); this.runtimeAgentId = runtimeAgentId; this.timestamp = timestamp; + this.runtimeAgentVersion = runtimeAgentVersion; } @Override diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java index 3f4026b8..bead520e 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java @@ -6,6 +6,7 @@ import com.solace.maas.ep.event.management.agent.plugin.jacoco.ExcludeFromJacocoGeneratedReport; import com.solace.maas.ep.event.management.agent.plugin.publisher.SolacePublisher; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.boot.info.BuildProperties; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -19,20 +20,28 @@ public class HeartbeatGenerator { private final SolacePublisher solacePublisher; private final String runtimeAgentId; private final String topic; + private final String runtimeAgentVersion; public HeartbeatGenerator(SolaceConfiguration solaceConfiguration, EventPortalProperties eventPortalProperties, - SolacePublisher solacePublisher) { + SolacePublisher solacePublisher, + BuildProperties buildProperties) { this.solacePublisher = solacePublisher; this.runtimeAgentId = eventPortalProperties.getRuntimeAgentId(); topic = solaceConfiguration.getTopicPrefix() + "heartbeat/v1"; - + this.runtimeAgentVersion = getFormattedVersion(buildProperties.getVersion()); } @Scheduled(fixedRate = 5000) public void sendHeartbeat() { - HeartbeatMessage message = new HeartbeatMessage(runtimeAgentId, Instant.now().toString()); + HeartbeatMessage message = new HeartbeatMessage(runtimeAgentId, Instant.now().toString(), runtimeAgentVersion); solacePublisher.publish(message, topic); } + private String getFormattedVersion(String version) { + if (version.endsWith("-SNAPSHOT")) { + return version.replace("-SNAPSHOT", ""); + } + return version; + } } diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/mop/MopTests.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/mop/MopTests.java index 44bc5dd2..04ebc961 100644 --- a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/mop/MopTests.java +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/mop/MopTests.java @@ -52,7 +52,7 @@ public void ack() { @Test public void testHeartbeatAgentMOPProtocol() { - HeartbeatMessage message = new HeartbeatMessage("runtimeId", "timestamp"); + HeartbeatMessage message = new HeartbeatMessage("runtimeId", "timestamp", "1.1.2"); assertEquals(message.getMopProtocol(), MOPProtocol.EMAHeartbeat); } }