Skip to content

Commit

Permalink
SWITCHYARD-1344 Add a demo for clustering
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Babo committed Mar 11, 2013
1 parent 8e65c89 commit faa3366
Show file tree
Hide file tree
Showing 32 changed files with 1,382 additions and 0 deletions.
81 changes: 81 additions & 0 deletions demos/cluster/README.md
@@ -0,0 +1,81 @@
# Cluster Demo Quickstart

This quickstart provides an example of deploying a set of applications containing a clustered service in SwitchYard. The quickstart consists of the following pieces:

* dealer : contains the Dealer Service which acts as consumer for the clustered Credit Service.
* credit : a clustered decision service implemented in Drools.
* client : the test driver for the application which can be used to send a request payload to the Dealer Service

The purpose of the quickstart is to demonstrate how the credit service can be clustered by deploying to a group of SwitchYard instances.

## Running the Example

You will need three SY instances and four terminal windows to run the clustering demo.

*1. Create three discrete instances of the SY runtime.*

This can be done by simply making copies of the standalone directory for each instance, e.g.
```
cd switchyard-as7-{version}
cp -R standalone node1
cp -R standalone node2
cp -R standalone node3
```

*2. Start each instance in a separate terminal window.*

_Window 1_
```
bin/standalone.sh -Djboss.node.name=node1 -Djboss.server.base.dir=node1 -c standalone-ha.xml
```
_Window 2_
```
bin/standalone.sh -Djboss.node.name=node2 -Djboss.server.base.dir=node2 -Djboss.socket.binding.port-offset=1000 -c standalone-ha.xml
```
_Window 3_
```
bin/standalone.sh -Djboss.node.name=node3 -Djboss.server.base.dir=node3 -Djboss.socket.binding.port-offset=2000 -c standalone-ha.xml
```

*3. In a separate terminal window deploy the dealer and credit applications.*

Build the client and service applications
```
cd quickstarts/demos/cluster
mvn package
```
Deploy Credit Service to node2 and node3.
```
cd credit
mvn -Ddeploy.port=10999 jboss-as:deploy
mvn -Ddeploy.port=11999 jboss-as:deploy
```
Deploy Dealer Service to node1.
```
cd ../dealer
mvn -Ddeploy.port=9999 jboss-as:deploy
```

*4. Run the test client and check output.*

Submit a message using the client project:
```
cd ../client
mvn exec:java
```
You should see the following output in the client terminal:
```
==================================
Was the offer accepted? true
==================================
```
If you submit multiple messages, you'll notice that the requests are split between the two instances where
the Credit Service is deployed. Check the console output on node2 and node3 to see where messages are being routed:
```
Credit Service : Approving credit for John Smith
```


## Further Reading

1. [SwitchYard Clustering](https://docs.jboss.org/author/display/SWITCHYARD/Clustering)
66 changes: 66 additions & 0 deletions demos/cluster/client/pom.xml
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2013, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<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>
<parent>
<groupId>org.switchyard.quickstarts</groupId>
<artifactId>switchyard-quickstart-parent</artifactId>
<version>0.8.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<groupId>org.switchyard.quickstarts.demos</groupId>
<artifactId>switchyard-quickstart-demo-cluster-client</artifactId>
<packaging>jar</packaging>
<name>Quickstart Demo: Cluster - Client</name>
<dependencies>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-remote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<debug>true</debug>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>org.switchyard.quickstarts.demo.cluster.RemoteClient</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,51 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.switchyard.quickstarts.demo.cluster;

public class Application {

private String name;
private int creditScore;
private boolean approved;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getCreditScore() {
return creditScore;
}

public void setCreditScore(int creditScore) {
this.creditScore = creditScore;
}

public boolean isApproved() {
return approved;
}

public void setApproved(boolean approved) {
this.approved = approved;
}

}
@@ -0,0 +1,41 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.switchyard.quickstarts.demo.cluster;

public class Car {

private String vehicleId;
private double price;

public String getVehicleId() {
return vehicleId;
}

public void setVehicleId(String vehicleId) {
this.vehicleId = vehicleId;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}
}
@@ -0,0 +1,42 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.switchyard.quickstarts.demo.cluster;

public class Deal {

private Offer offer;
private boolean accepted;

public Offer getOffer() {
return offer;
}

public void setOffer(Offer offer) {
this.offer = offer;
}

public boolean isAccepted() {
return accepted;
}

public void setAccepted(boolean accepted) {
this.accepted = accepted;
}

}
@@ -0,0 +1,51 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.switchyard.quickstarts.demo.cluster;

public class Offer {

private Application application;
private Car car;
private double amount;

public Application getApplication() {
return application;
}

public void setApplication(Application application) {
this.application = application;
}

public Car getCar() {
return car;
}

public void setCar(Car car) {
this.car = car;
}

public double getAmount() {
return amount;
}

public void setAmount(double amount) {
this.amount = amount;
}

}

0 comments on commit faa3366

Please sign in to comment.