Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-11882

ServiceDefinition.metadata not passed to RibbonServiceLoadBalancer

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.20.0
    • Component/s: camel-ribbon
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      I tried to write a Ribbon Load Balancer test that would send requests to two application paths on the same server and port. Because org.apache.camel.cloud.ServiceDefinition has no notion of context path, I used the ServiceDefinition.metadata to define it and in the serviceCall I used an expression .expression().simple("jetty:http://${header.CamelServiceCallServiceHost}:${header.CamelServiceCallServicePort}/${header.CamelServiceCallServiceMeta[contextPath]}") to use it.
      However, the test is not passing because RibbonServiceLoadBalancer.RibbonServerList.asRibbonServerList(List<ServiceDefinition>) is not passing the medata map to RibbonServiceDefinition. The test passes as expected when RibbonServerList.asRibbonServerList() is fixed.

      Here is the test:

      package org.apache.camel.component.ribbon.cloud;
      
      import java.util.Collections;
      
      import org.apache.camel.RoutesBuilder;
      import org.apache.camel.builder.RouteBuilder;
      import org.apache.camel.component.ribbon.RibbonConfiguration;
      import org.apache.camel.impl.cloud.StaticServiceDiscovery;
      import org.apache.camel.test.junit4.CamelTestSupport;
      import org.junit.Test;
      
      public class RibbonServiceCallRouteMetadataTest extends CamelTestSupport {
          @Test
          public void testServiceCall() throws Exception {
              getMockEndpoint("mock:app1").expectedMessageCount(1);
              getMockEndpoint("mock:app2").expectedMessageCount(1);
              getMockEndpoint("mock:result").expectedMessageCount(2);
      
              String out = template.requestBody("direct:start", null, String.class);
              String out2 = template.requestBody("direct:start", null, String.class);
              assertEquals("app2", out);
              assertEquals("app1", out2);
      
              assertMockEndpointsSatisfied();
          }
      
          @Override
          protected RoutesBuilder createRouteBuilder() throws Exception {
              return new RouteBuilder() {
                  @Override
                  public void configure() throws Exception {
                      // setup a static ribbon server list with these 2 servers to start with
                      StaticServiceDiscovery servers = new StaticServiceDiscovery();
                      servers.addServer("myService", "localhost", 9090, Collections.singletonMap("contextPath", "app1"));
                      servers.addServer("myService", "localhost", 9090, Collections.singletonMap("contextPath", "app2"));
      
                      RibbonConfiguration configuration = new RibbonConfiguration();
                      RibbonServiceLoadBalancer loadBalancer = new RibbonServiceLoadBalancer(configuration);
      
                      from("direct:start")
                          .serviceCall()
                              .name("myService")
                              .expression().simple("jetty:http://${header.CamelServiceCallServiceHost}:${header.CamelServiceCallServicePort}/${header.CamelServiceCallServiceMeta[contextPath]}")
                              .loadBalancer(loadBalancer)
                              .serviceDiscovery(servers)
                              .end()
                          .to("mock:result");
                      from("jetty:http://localhost:9090/app1")
                          .to("mock:app1")
                          .transform().constant("app1");
                      from("jetty:http://localhost:9090/app2")
                          .to("mock:app2")
                          .transform().constant("app2");
                  }
              };
          }
      }
      
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ppalaga Peter Palaga
                Reporter:
                ppalaga Peter Palaga
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: