ServiceCall EIP

Available as of Camel 2.18

The serviceCall EIP allows to call remote services in a distributed system. The service to call is looked up in a service registry of some sorts such as Kubernetes, Consul, etcd, Zookeeper. The EIP separates the configuration of the service registry from the calling of the service. 

Maven users will need to add the dependency for the service registry supported from the following:

  • camel-consul
  • camel-etcd
  • camel-kubernetes
  • camel-ribbon

Each implementation has their own set of configuration.

Syntax

When calling a service you may just refer to the name of the service in the EIP as shown below:

And in XML DSL:

Camel will then lookup a service with the name foo from the chosen Camel component that integrates with the service registry. The lookup returns a set of IP:PORT pairs that refer to a list of active servers that host the remote service. Camel will then select a server at random from the list to use and then build a Camel URI with the chosen IP and PORT number.

By default Camel uses the HTTP component, so the example above will resolve into a Camel URI that is called by a dynamic toD endpoint as shown:

You can also call the service using URI parameters such as beer=yes:

You can also provide a context-path such as shown:

Service Name to Camel URI Examples

So as you can see above the service name is resolved as a Camel endpoint URI, and here is a few more examples (where -> shows the resolution of the Camel URI):

If you want full control of the resolved URI you can provide an additional URI parameter where you specify the Camel URI as you want. In the URI you can use the service name which are then resolved to IP:PORT as shown:

In the example above we want to call a service named myService and we can control the resolved URI as in the second parameter. Notice how in the first example we can use serviceName.host and serviceName.port to refer to either the IP or PORT. If you just use serviceName then it's resolved as IP:PORT.

Configuring Service Call

By default Camel will call the service using the HTTP component, but you can configure to use a different component such as HTTP4Netty4 HTTP as shown:

In XML DSL:

Common Configuration

These are the common configuration that each implementation is sharing.

Name

Default
Value

Description

clientProperty

 

These properties are specific to what service call implementation are in use.

For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

component

http

Sets the default Camel component to use for calling the remote service. By default the http component is used.

You can configure this to use netty4-http, jettyrestlet or some other components of choice.
If the service does not use the HTTP protocol then other components such as mqtt, jmsamqp etc can be used.
If the service call has been configured using a URI the component specified in the URI is used instead of this default component.

loadBalancerRef

 

Sets a reference to a custom org.apache.camel.spi.ServiceCallLoadBalancer to use.

serverListStrategyRef

 

Sets a reference to a custom org.apache.camel.spi.ServiceCallServerListStrategy to use.

 

Kubernetes Configuration

Name

Default Value

Description

apiVersion

 

Kubernetes API version when using client lookup.

caCertData

 

Sets the Certificate Authority data when using client lookup.

caCertFile

 

Sets the Certificate Authority data that are loaded from the file when using client lookup.

clientCertData

 

Sets the Client Certificate data when using client lookup.

clientCertFile

 

Sets the Client Certificate data that are loaded from the file when using client lookup.

clientKeyAlgo

 

Sets the Client Keystore algorithm, such as RSA when using client lookup.

clientKeyData

 

Sets the Client Keystore data when using client lookup.

clientKeyFile

 

Sets the Client Keystore data that are loaded from the file when using client lookup.

clientKeyPassphrase

 

Sets the Client Keystore passphrase when using client lookup.

dnsDomain

 

Sets the DNS domain to use for dns lookup.

lookup

environment

The choice of strategy used to lookup the service.

The list of lookup strategies are:

Lookup Strategy

Description

environment

Use environment variables.

dns

Use DNS domain names.

client

Use Java Client to call the Kubernetes master API and query which servers are actively hosting the service.

masterUrl

 

The URL for the Kubernetes master when using client lookup.

namespace

 

The Kubernetes namespace to use. By default the namespace's name is taken from the environment variable KUBERNETES_MASTER.

oauthToken

 

Sets the OAUTH token for authentication (instead of username/password) when using client lookup.

password

 

Sets the password for authentication when using client lookup.

trustCerts

false

Sets whether to turn on trust certificate check when using client lookup.

username

 

Sets the username for authentication when using client lookup.

Ribbon Configuration

Currently no ribbon specific options yet.

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram