Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #61 from patientsknowbest/feature/pubsub-routes
Browse files Browse the repository at this point in the history
Feature/pubsub routes
  • Loading branch information
MFAshby authored Jul 21, 2021
2 parents ae790b7 + fc62df4 commit dee6385
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 10 deletions.
4 changes: 4 additions & 0 deletions config/src/main/java/com/pkb/common/config/BaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ default boolean isPubSubTestControlEnabled() {
return getConfigStorage().getBoolean("pubsub.testcontrolenabled", false);
}

default String getEnvironmentName() {
return getConfigStorage().getString("environment.name", "NOT_SET");
}

/**
* @param protocol defaults to http
* @param host valid value required
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<module>testsupport</module>
<module>spring-boot-infrastructure</module>
<module>spring-boot-kotlin-infrastructure</module>
<module>pubsub</module>
</modules>

<dependencyManagement>
Expand Down
69 changes: 69 additions & 0 deletions pubsub/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>pkb-common</artifactId>
<groupId>com.pkb.pkbcommon</groupId>
<version>${revision}${changelist}</version>
</parent>

<artifactId>pubsub</artifactId>
<name>pkb-common/pubsub</name>

<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-google-pubsub</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<configuration>
<stringType>String</stringType>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
<outputDirectory>${project.basedir}/target/generated-sources/main/java/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
12 changes: 12 additions & 0 deletions pubsub/src/main/avro/QuestionnaireCompletedMessage.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"namespace": "com.pkb.common.pubsub.payload",
"type": "record",
"name": "QuestionnaireCompletedMessage",
"fields": [
{"name": "patientId", "type": "string"},
{"name": "questionnaireId", "type": "string"},
{"name": "questionnaireResponseId", "type": "string"},
{"name": "questionnaireName", "type": "string"},
{"name": "sourceCluster", "type": "string"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pkb.common.pubsub;

import com.pkb.common.pubsub.config.IGeneralPubsubConfig;
import org.apache.camel.Endpoint;
import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;

public abstract class QuestionnaireCompletedRoute extends RouteBuilder {

@EndpointInject(property = "questionnaireEventTopicUri")
private Endpoint questionnaireEventTopic;

public abstract IGeneralPubsubConfig config();

public String getQuestionnaireEventTopicUri() {
return String.format("google-pubsub:%s:questionnaire_event_topic", config().getProject());
}

@Override
public void configure() {
from("direct:questionnaire_event_topic")
.to(questionnaireEventTopic);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pkb.common.pubsub.config;

public class GeneralPubsubConfig implements IGeneralPubsubConfig {

private final String project;

public GeneralPubsubConfig(String project) {
this.project = project;
}

@Override
public String getProject() {
return project;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pkb.common.pubsub.config;

public interface IGeneralPubsubConfig {

String getProject();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.apache.camel.Endpoint;
import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.google.pubsub.GooglePubsubComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -68,15 +67,6 @@ public String getTestControlResponseTopicUri() {
*/
@Override
public void configure() throws Exception {

// configure the component - TODO (next ticket?): this needs to get moved out as it should be shared across all routes
// that use the pubsub component. Possibly by definining a CamelContextConfiguration @Bean (or equivalent)
GooglePubsubComponent component = (GooglePubsubComponent) getContext().getComponent("google-pubsub");
component.setPublisherCacheTimeout(0); //not necessary to expire
if (config().getEmulatorEndpoint().isPresent()) {
component.setEndpoint(config().getEmulatorEndpoint().get());
}

//announce the app is ready to receive test control messages
if (config().getShouldRegisterStartup()) {
from("timer:startup?repeatCount=1")
Expand All @@ -102,6 +92,7 @@ public void configure() throws Exception {
}
}


public TestControlResponse handleTestSupportRequest(TestControlRequest request) {
MessageType messageType = request.getMessageType();
LOGGER.info(String.format(config().getApplicationName() + ": handleRequest messageType %s", messageType));
Expand Down

0 comments on commit dee6385

Please sign in to comment.