-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Used Zookeeper for cluster discovery rather than Hazelcast
- Loading branch information
1 parent
f58fab0
commit c61cbf8
Showing
6 changed files
with
241 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,135 @@ | ||
<?xml version="1.0"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.vertx</groupId> | ||
<artifactId>vertx-cluster</artifactId> | ||
<version>3.2.1</version> | ||
<name>spring-example</name> | ||
<groupId>io.vertx</groupId> | ||
<artifactId>vertx-cluster-example</artifactId> | ||
<version>3.2.1</version> | ||
<name>spring-example</name> | ||
|
||
<properties> | ||
<!-- the main verticle class name --> | ||
<main.class>io.vertx.examples.spring.SpringExampleRunner</main.class> | ||
<spring.data.jpa.version>1.8.0.RELEASE</spring.data.jpa.version> | ||
<h2.version>1.4.187</h2.version> | ||
<slf4j.version>1.7.12</slf4j.version> | ||
<hibernate.version>4.3.10.Final</hibernate.version> | ||
</properties> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.3.2.RELEASE</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.vertx</groupId> | ||
<artifactId>vertx-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.vertx</groupId> | ||
<artifactId>vertx-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.vertx</groupId> | ||
<artifactId>vertx-hazelcast</artifactId> | ||
<version>3.2.1</version> | ||
</dependency> | ||
<properties> | ||
<!-- the main verticle class name --> | ||
<kotlin.version>1.1.2-4</kotlin.version> | ||
<boot.version>1.3.2.RELEASE</boot.version> | ||
<main.class>io.vertx.examples.spring.SpringExampleRunner</main.class> | ||
<spring.data.jpa.version>1.8.0.RELEASE</spring.data.jpa.version> | ||
<h2.version>1.4.187</h2.version> | ||
<slf4j.version>1.7.12</slf4j.version> | ||
<hibernate.version>4.3.10.Final</hibernate.version> | ||
<vertx.version>3.4.1</vertx.version> | ||
</properties> | ||
|
||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>${h2.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
<!-- <dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>${boot.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement>--> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.vertx</groupId> | ||
<artifactId>vertx-core</artifactId> | ||
<version>${vertx.version}</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/io.vertx/vertx-zookeeper --> | ||
<dependency> | ||
<groupId>io.vertx</groupId> | ||
<artifactId>vertx-zookeeper</artifactId> | ||
<version>${vertx.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.vertx</groupId> | ||
<artifactId>vertx-lang-kotlin</artifactId> | ||
<version>${vertx.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>${h2.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-entitymanager</artifactId> | ||
<version>${hibernate.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-entitymanager</artifactId> | ||
<version>${hibernate.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<!-- We specify the Maven compiler plugin as we need to set it to Java 1.8 --> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</dependencies> | ||
|
||
<!-- | ||
You only need the part below if you want to build your application into a fat executable jar. | ||
This is a jar that contains all the dependencies required to run it, so you can just run it with | ||
java -jar | ||
--> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.3</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<manifestEntries> | ||
<Main-Class>${main.class}</Main-Class> | ||
</manifestEntries> | ||
</transformer> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> | ||
<resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource> | ||
</transformer> | ||
</transformers> | ||
<artifactSet> | ||
</artifactSet> | ||
<outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<build> | ||
<plugins> | ||
<!-- We specify the Maven compiler plugin as we need to set it to Java 1.8 --> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>process-sources</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
<configuration> | ||
<sourceDirs> | ||
<source>src/main/resources</source> | ||
<source>src/main/java</source> | ||
</sourceDirs> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>test-compile</id> | ||
<phase>process-test-sources</phase> | ||
<goals> | ||
<goal>test-compile</goal> | ||
</goals> | ||
<configuration> | ||
<sourceDirs></sourceDirs> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
|
||
</build> | ||
</project> |
33 changes: 25 additions & 8 deletions
33
src/main/java/io/vertx/examples/spring/SpringExampleRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/io/vertx/examples/spring/verticle/KotlinVerticle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.vertx.examples.spring.verticle | ||
|
||
|
||
/** | ||
* Created by marutsingh on 5/27/17. | ||
*/ | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import io.vertx.core.AbstractVerticle | ||
import io.vertx.core.Handler | ||
import io.vertx.core.eventbus.Message | ||
import io.vertx.examples.spring.service.ProductService | ||
|
||
|
||
/** | ||
* Simple verticle to wrap a Spring service bean - note we wrap the service call | ||
* in executeBlocking, because we know it's going to be a JDBC call which blocks. | ||
* As a general principle with Spring beans, the default assumption should be that it will block unless you | ||
* know for sure otherwise (in other words use executeBlocking unless you know for sure your service call will be | ||
* extremely quick to respond) | ||
*/ | ||
class SpringDemoVerticle1 : AbstractVerticle() { | ||
|
||
private val mapper = ObjectMapper() | ||
|
||
/*fun allProductsHandler(service: ProductService): Handler<Message<String>> { | ||
System.out.println("Hello World!") | ||
return { msg -> | ||
System.out.println("1 received message.body() = " | ||
+ message.body()); | ||
} | ||
// throw new Exception(""); | ||
*//*return msg -> vertx.<String>executeBlocking(future -> { | ||
throw new Exception(""); | ||
try { | ||
future.complete(mapper.writeValueAsString(service.getAllProducts())); | ||
} catch (JsonProcessingException e) { | ||
System.out.println("Failed to serialize result"); | ||
future.fail(e); | ||
} | ||
}, | ||
result -> { | ||
if (result.succeeded()) { | ||
msg.reply(result.result()); | ||
} else { | ||
msg.reply(result.cause().toString()); | ||
} | ||
});*//* | ||
} | ||
*/ | ||
override fun start() { | ||
super.start() | ||
val productService = ProductService() | ||
|
||
vertx.eventBus().consumer(ALL_PRODUCTS_ADDRESS, { message: Message<String> -> | ||
System.out.println("1 received message.body() = " | ||
+ message.body()); | ||
}) | ||
|
||
//Start consuming events | ||
/*vertx.eventBus().consumer<String>(ALL_PRODUCTS_ADDRESS, { | ||
allProductsHandler(productService) | ||
})*/ | ||
|
||
} | ||
|
||
companion object { | ||
|
||
public val ALL_PRODUCTS_ADDRESS: String = "example.all.products" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.