Skip to content

Commit

Permalink
initial microservice client example
Browse files Browse the repository at this point in the history
  • Loading branch information
salaboy committed Aug 2, 2017
1 parent 86500b3 commit 7cf36db
Show file tree
Hide file tree
Showing 9 changed files with 638 additions and 22 deletions.
35 changes: 13 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/target
/local

# Eclipse, Netbeans and IntelliJ files
/.*
!.gitignore
/nbproject
/*.ipr
/*.iws
/*.iml

# Repository wide ignore mac DS_Store files
.DS_Store
13 changes: 13 additions & 0 deletions activiti-microservice-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/target
/local

# Eclipse, Netbeans and IntelliJ files
/.*
!.gitignore
/nbproject
/*.ipr
/*.iws
/*.iml

# Repository wide ignore mac DS_Store files
.DS_Store
60 changes: 60 additions & 0 deletions activiti-microservice-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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>
<groupId>org.activiti</groupId>
<artifactId>activiti-examples-root</artifactId>
<version>7.0.0-SNAPSHOT</version>
</parent>

<artifactId>activiti-microservice-client</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.activiti.example.microservice.client;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "commandType")
public interface Command {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.activiti.example.microservice.client;

import org.springframework.cloud.stream.annotation.Input;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;

public interface CommandChannels {

String CMD_OUTPUT = "cmdOutput";

String CMD_RESULTS = "cmdResults";

@Output(CMD_OUTPUT)
MessageChannel cmdOutput();

@Input(CMD_RESULTS)
SubscribableChannel cmdResults();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.activiti.example.microservice.client;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableBinding(CommandChannels.class)
@RestController
@RequestMapping(value = "/api/", produces = MediaTypes.HAL_JSON_VALUE)
public class MicroServiceExampleApplication {

@Autowired
private MessageChannel cmdOutput;

public static void main(String[] args) {
SpringApplication.run(MicroServiceExampleApplication.class,
args);
}

@RequestMapping(method = RequestMethod.POST, path = "/send")
public ResponseEntity sendMessage() {
Map<String, String> vars = new HashMap<>();
vars.put("hey", "one");
StartProcessCmd cmd = new StartProcessCmd("myId", vars);
cmdOutput.send((MessageBuilder.withPayload(cmd).build()));
return new ResponseEntity<String>(cmd + " ack!",
HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.activiti.example.microservice.client;

import java.util.Map;


public class StartProcessCmd implements Command {

private String processDefinitionKey;
private Map<String, String> variables;

public StartProcessCmd() {
}

public StartProcessCmd(String processDefinitionKey,
Map<String, String> variables) {
this.processDefinitionKey = processDefinitionKey;
this.variables = variables;
}

public String getProcessDefinitionKey() {
return processDefinitionKey;
}

public Map<String, String> getVariables() {
return variables;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring.cloud.stream.bindings.cmdOutput.destination=commandConsumer
spring.cloud.stream.bindings.cmdOutput.contentType=application/json
server.port=8081
Loading

0 comments on commit 7cf36db

Please sign in to comment.