Skip to content

Commit

Permalink
Merge pull request #124 from SolaceProducts/pwang/DATAGO-62205
Browse files Browse the repository at this point in the history
add EMA version to heartbeat message
  • Loading branch information
pwang1997 authored Oct 13, 2023
2 parents 4e9349f + 48290c2 commit fd986a2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
14 changes: 13 additions & 1 deletion service/application/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.solace.maas</groupId>
Expand Down Expand Up @@ -341,6 +342,17 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ 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)
.withVersion("1")
.withUhFlag(MOPUHFlag.ignore);
this.runtimeAgentId = runtimeAgentId;
this.timestamp = timestamp;
this.runtimeAgentVersion = runtimeAgentVersion;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit fd986a2

Please sign in to comment.