By:
James R. Perkins <jperkins@redhat.com>
In short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.- Martin Fowler, ThoughtWorks
WildFly | WildFly Swarm |
---|---|
|
|
WildFly | WildFly Swarm |
---|---|
|
|
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>1.0.0.Final</version>
<configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
mvn package
mvn wildfly-swarm:run
- or -
java -jar target/myapp-swarm.jar
org.wildfly.swarm:wildfly-swarm-plugin
to our pom
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>datasources</artifactId>
</dependency>
<fractionDetectMode>force</fractionDetectMode>
main()
methodmain()
method is the entry point to a Swarm appmain()
methodmain()
method
public static void main(final String[] args) throws Exception {
final Container container = new Container();
final JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "myapp.war");
deployment.addClass(MyResource.class);
deployment.addClass(NotFoundExceptionMapper.class);
deployment.addAllDependencies();
container.start().deploy(deployment);
}
<configuration>
<mainClass>org.wildfly.swarm.examples.jaxrs.shrinkwrap.Main</mainClass>
</configuration>
There are two options for configuring the container:
final Container container = new Container()
.fraction(new DatasourcesFraction()
.jdbcDriver("h2", (d) -> {
d.driverClassName("org.h2.Driver");
d.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource");
d.driverModuleName("com.h2database.h2");
})
.dataSource("ExampleDS", (ds) -> {
ds.driverName("h2");
ds.connectionUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
ds.userName("sa");
ds.password("sa");
})
);
final ClassLoader cl = Main.class.getClassLoader();
final URL xmlConfig = cl.getResource("standalone.xml");
final Container container = new Container()
.withXmlConfig(xmlConfig);