Search in sources :

Example 1 with SequentialStrategy

use of org.apache.cxf.clustering.SequentialStrategy in project camel by apache.

the class LoadDistributorFeatureTest method startRoute.

private void startRoute(DefaultCamelContext ctx, final String proxy, final String real) throws Exception {
    ctx.addRoutes(new RouteBuilder() {

        public void configure() {
            List<String> serviceList = new ArrayList<String>();
            serviceList.add(SERVICE_ADDRESS_1);
            serviceList.add(SERVICE_ADDRESS_2);
            SequentialStrategy strategy = new SequentialStrategy();
            strategy.setAlternateAddresses(serviceList);
            LoadDistributorFeature ldf = new LoadDistributorFeature();
            ldf.setStrategy(strategy);
            CxfEndpoint endpoint = (CxfEndpoint) (endpoint(real));
            endpoint.getFeatures().add(ldf);
            from(proxy).to(endpoint);
        }
    });
    ctx.start();
}
Also used : SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) RouteBuilder(org.apache.camel.builder.RouteBuilder) LoadDistributorFeature(org.apache.cxf.clustering.LoadDistributorFeature) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with SequentialStrategy

use of org.apache.cxf.clustering.SequentialStrategy in project testcases by coheigea.

the class FailoverTest method testFailoverFeature.

@org.junit.Test
public void testFailoverFeature() throws Exception {
    URL busFile = FailoverTest.class.getResource("cxf-client.xml");
    FailoverFeature feature = new FailoverFeature();
    SequentialStrategy strategy = new SequentialStrategy();
    List<String> addresses = new ArrayList<>();
    addresses.add("http://localhost:" + PORT2 + "/doubleit/services");
    strategy.setAlternateAddresses(addresses);
    feature.setStrategy(strategy);
    String address = "http://localhost:" + PORT1 + "/doubleit/services";
    WebClient client = WebClient.create(address, null, Collections.singletonList(feature), busFile.toString());
    client = client.type("application/xml");
    Number numberToDouble = new Number();
    numberToDouble.setDescription("This is the number to double");
    numberToDouble.setNumber(25);
    // First call is successful to PORT1
    Response response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
    // Second call fails over to PORT2
    response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
}
Also used : Response(javax.ws.rs.core.Response) SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) Number(org.apache.coheigea.cxf.failover.common.Number) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) CircuitBreakerFailoverFeature(org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 3 with SequentialStrategy

use of org.apache.cxf.clustering.SequentialStrategy in project testcases by coheigea.

the class FailoverTest method testCircuitBreaker.

@org.junit.Test
public void testCircuitBreaker() throws Exception {
    URL busFile = FailoverTest.class.getResource("cxf-client.xml");
    CircuitBreakerFailoverFeature feature = new CircuitBreakerFailoverFeature();
    feature.setThreshold(2);
    SequentialStrategy strategy = new SequentialStrategy();
    strategy.setDelayBetweenRetries(3000L);
    List<String> addresses = new ArrayList<>();
    addresses.add("http://localhost:" + PORT2 + "/doubleit/services");
    strategy.setAlternateAddresses(addresses);
    feature.setStrategy(strategy);
    String address = "http://localhost:" + PORT1 + "/doubleit/services";
    WebClient client = WebClient.create(address, null, Collections.singletonList(feature), busFile.toString());
    client = client.type("application/xml");
    Number numberToDouble = new Number();
    numberToDouble.setDescription("This is the number to double");
    numberToDouble.setNumber(25);
    // First call is successful to PORT1
    Response response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
    // Second call fails over to PORT2
    response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
}
Also used : Response(javax.ws.rs.core.Response) SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) Number(org.apache.coheigea.cxf.failover.common.Number) CircuitBreakerFailoverFeature(org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 4 with SequentialStrategy

use of org.apache.cxf.clustering.SequentialStrategy in project cxf by apache.

the class CircuitBreakerFailoverTest method customizeFeature.

private FailoverFeature customizeFeature(CircuitBreakerFailoverFeature feature, boolean random, String... address) {
    List<String> alternateAddresses = new ArrayList<>();
    for (String s : address) {
        alternateAddresses.add(s);
    }
    if (!random) {
        SequentialStrategy strategy = new SequentialStrategy();
        strategy.setAlternateAddresses(alternateAddresses);
        feature.setStrategy(strategy);
    } else {
        RandomStrategy strategy = new RandomStrategy();
        strategy.setAlternateAddresses(alternateAddresses);
        feature.setStrategy(strategy);
    }
    return feature;
}
Also used : SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) RandomStrategy(org.apache.cxf.clustering.RandomStrategy) ArrayList(java.util.ArrayList)

Example 5 with SequentialStrategy

use of org.apache.cxf.clustering.SequentialStrategy in project cxf by apache.

the class LoadDistributorTest method getFeature.

private FailoverFeature getFeature(String... address) {
    FailoverFeature feature = new FailoverFeature();
    List<String> alternateAddresses = new ArrayList<>();
    for (String s : address) {
        alternateAddresses.add(s);
    }
    SequentialStrategy strategy = new SequentialStrategy();
    strategy.setAlternateAddresses(alternateAddresses);
    feature.setStrategy(strategy);
    LoadDistributorTargetSelector selector = new LoadDistributorTargetSelector();
    selector.setFailover(false);
    feature.setTargetSelector(selector);
    return feature;
}
Also used : SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) LoadDistributorTargetSelector(org.apache.cxf.clustering.LoadDistributorTargetSelector) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)10 SequentialStrategy (org.apache.cxf.clustering.SequentialStrategy)10 WebClient (org.apache.cxf.jaxrs.client.WebClient)5 URL (java.net.URL)4 FailoverFeature (org.apache.cxf.clustering.FailoverFeature)4 LoadDistributorFeature (org.apache.cxf.clustering.LoadDistributorFeature)4 Response (javax.ws.rs.core.Response)3 Number (org.apache.coheigea.cxf.failover.common.Number)3 CircuitBreakerFailoverFeature (org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature)3 Book (org.apache.cxf.systest.jaxrs.Book)3 Test (org.junit.Test)3 RandomStrategy (org.apache.cxf.clustering.RandomStrategy)2 List (java.util.List)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 FailoverTargetSelector (org.apache.cxf.clustering.FailoverTargetSelector)1 LoadDistributorTargetSelector (org.apache.cxf.clustering.LoadDistributorTargetSelector)1 BookStore (org.apache.cxf.systest.jaxrs.BookStore)1