Skip to content
This repository was archived by the owner on Dec 2, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Profiles-Blog-Monolithic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/
20 changes: 20 additions & 0 deletions Profiles-Blog-Monolithic/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
description = 'Profiles-Blog-Monolithic'

apply plugin: 'war'

war {
baseName = 'Profiles-Blog-Monolithic'
version = '0.0.1-SNAPSHOT'
}

dependencies {
compile project(':Profiles-Blog-Sender')
compile project(':Profiles-Blog-Receiver')
}

// Ensure each project uses a different remote debug port
def remoteDebugPort = '5001'

if (!project.hasProperty('prod')) {
bootRun.jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=" + remoteDebugPort]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.jdw.blog;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MonolithicMain {

public static void main(String[] args) throws Exception {
SpringApplication.run(new Class[]{SenderMain.class,ReceiverMain.class}, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server.port=9001
sender.target.hostport=localhost:9001
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void receivePayload(@RequestBody Payload payload) {
receiveCountService.incrementReceiveCount(payload.getPayloadType());
}

@RequestMapping("/{payloadType}/count")
@RequestMapping("/receiver/{payloadType}/count")
public ReceiveCount findReceiveCount(@PathVariable("payloadType") PayloadType payloadType) {
return receiveCountService.findReceiveCount(payloadType);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jdw.blog.sender;

import org.springframework.beans.factory.annotation.Value;
import java.util.Arrays;

import javax.annotation.PostConstruct;
Expand All @@ -20,8 +21,12 @@
public class PayloadSender {

private RestTemplate restTemplate;

@Value("${sender.target.hostport}")
private String serverHostPort;

@PostConstruct

@PostConstruct
public void initialize() {
restTemplate = new RestTemplate();

Expand All @@ -48,10 +53,18 @@ public void sendPayloadToReceiver(PayloadType payloadType) {
// Rudimentary destination hard-coding
// Only sends to a local receiver
// Receiver's port taken from Profiles-Blog-Receiver's application.properties
String url = "http://localhost:9002/receive";
String url = "http://"+serverHostPort+"/receive";

// Invoke the endpoint in the Profiles-Blog-Receiver project
restTemplate.postForEntity(url, payload, Void.class);
}

public String getServerHostPort() {
return serverHostPort;
}

public void setServerHostPort(String serverHostPort) {
this.serverHostPort = serverHostPort;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public SendCount sendPayload(@PathVariable("payloadType") PayloadType payloadTyp
return sendCountService.incrementSendCount(payloadType);
}

@RequestMapping("/{payloadType}/count")
@RequestMapping("/sender/{payloadType}/count")
public SendCount findSendCount(@PathVariable("payloadType") PayloadType payloadType) {
return sendCountService.findSendCount(payloadType);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
server.port=9001
sender.target.hostport=localhost:9002
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ gradle -Pdev bootRun
Or, if in the parent project's directory, individual projects can be targeted using their name:
gradle -Pdev Profiles-Blog-Sender:bootRun

You can also run all subprojects in a monolithic stack of the app with:
gradle -Ptest Profiles-Blog-Monolithic:bootRun

See common\_test\_application.properties and common\_dev\_application.properties for information about where each database is located.

The prod profile requires database credentials to be passed using -P arguments as follows:
Expand All @@ -26,13 +29,13 @@ http://localhost:9001/TEST1/send
Sends a payload of the type specified in the URL to the Profiles-Blog-Sender project.
Sample Response" {"payloadType":"TEST1","timesSent":1}

http://localhost:9001/TEST1/count
http://localhost:9001/sender/TEST1/count
Displays the current number of times the specified payload type has been sent.
Sample Response: {"payloadType":"TEST1","timesSent":1}

**Profiles-Blog-Receiver supports one HTTP GET command:**

http://localhost:9002/TEST1/count
http://localhost:9002/receiver/TEST1/count
Displays the current number of times the specified payload type has been received.
Sample Response: {"payloadType":"TEST1","timesReceived":1}

Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ rootProject.name = 'Profiles-Blog'
include 'Profiles-Blog-Common'
include 'Profiles-Blog-Sender'
include 'Profiles-Blog-Receiver'
include 'Profiles-Blog-Monolithic'