Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/juanavelez/vertx-spring-verticle-factory
An implementation of a Vert.x Verticle Factory using Spring
https://github.com/juanavelez/vertx-spring-verticle-factory
reactive spring vertx
Last synced: about 1 month ago
JSON representation
An implementation of a Vert.x Verticle Factory using Spring
- Host: GitHub
- URL: https://github.com/juanavelez/vertx-spring-verticle-factory
- Owner: juanavelez
- License: apache-2.0
- Created: 2016-11-02T20:41:41.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-01-11T02:30:21.000Z (almost 6 years ago)
- Last Synced: 2024-09-27T07:42:30.007Z (about 1 month ago)
- Topics: reactive, spring, vertx
- Language: Java
- Homepage:
- Size: 27.3 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- vertx-awesome - Vert.x Spring Verticle Factory - A Vert.x Verticle Factory that makes use of Spring to obtain and configure Verticles. (Dependency Injection)
README
# Vert.x Spring Verticle Factory
[![Build Status](https://travis-ci.org/juanavelez/vertx-spring-verticle-factory.svg?branch=master)](https://travis-ci.org/juanavelez/vertx-spring-verticle-factory)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.chibchasoft/vertx-spring-verticle-factory/badge.svg)](https://search.maven.org/#search%7Cga%7C1%7Ccom.chibchasoft.vertx-spring-verticle-factory)
[![codecov](https://codecov.io/gh/juanavelez/vertx-spring-verticle-factory/branch/master/graph/badge.svg)](https://codecov.io/gh/juanavelez/vertx-spring-verticle-factory)An implementation of a Vert.x Verticle Factory where the verticles are obtained via a Spring Application Context. The verticles must exist as Spring Beans whose bean scope must be **PROTOTYPE**. The verticles are free to use all the Spring-provided capabilities to set themselves up. This factory's createVerticle method can be considered slow, hence blockingCreate() returns true.
This implementation relies on setting a Spring Application Context (using com.chibchasoft.vertx.spring.ApplicationContextProvider) before Vert.x Verticles are deployed. The prefix for this verticle is "spring:" and the verticle name is the spring bean id/name assigned to such verticle.
## Usage: ##
Vert.x Spring Verticle Factory is published to the [maven public repo](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.chibchasoft%22%20AND%20a%3A%22vertx-spring-verticle-factory%22).
Add the vertx-spring-verticle-factory dependency to your project, in case of maven like this:
```xml
com.chibchasoft
vertx-spring-verticle-factory
VERSION
```
where VERSION is [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.chibchasoft/vertx-spring-verticle-factory/badge.svg)](https://search.maven.org/#search%7Cga%7C1%7Ccom.chibchasoft.vertx-spring-verticle-factory)Then create a Spring Application Context (either using an XML or annotation approach) and assign it to the ApplicationContextProvider:
```java
ApplicationContext appCtx = new AnnotationConfigApplicationContext(AnnotatedSpringConfiguration.class);
ApplicationContextProvider.setApplicationContext(appCtx);
```Proceed to deploy the spring-bean-based verticle like this:
```java
Vertx vertx = Vertx.vertx();
vertx.deployVerticle("spring:mySpringVerticle", new DeploymentOptions().setInstances(2).setWorker(true));
```**NOTE**: The Spring Application Context set in the ApplicationContextProvider is used for all the verticles created using the Spring Verticle Factory up to the point where it is changed. Once changed, the Spring Verticle Factory will use the new one when creating new verticles.
The verticle class itself can use any Spring capabilities, for example:
```java
@Component("mySpringVerticle")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class MySpringVerticle extends AbstractVerticle {
@Value("${my.property}")
private String theProperty;@Inject
private MyService myService;@PostConstruct
public void init() {
System.out.println("Perform initialization in here");
}
}
```