cLoadBalancer
balancing policy.
cLoadBalancer Standard properties
These properties are used to configure cLoadBalancer running in the Standard Job framework.
The Standard
cLoadBalancer component belongs to the Routing family.
Basic
settings
Strategy |
Select between Random, Round |
Random |
The receiving endpoint is chosen randomly at each exchange. |
Round Robin | Messages are distributed according to the round robin method which distributes the load evenly. |
Sticky |
Language: Select the language |
Expression: Type in the |
|
Topic |
Select this option to send all the messages to all the |
Failover |
Basic mode: By default, the |
Specify exceptions: Specify |
|
Use with Round robin: Select From the Maximum failover –Attempt forever: always attempts to
–Never failover: gives up –A number of
Inherit error
Use Round robin: Select |
|
Custom |
Load balancer: Type in the |
Usage
Usage rule |
cLoadBalancer is used as a middle component in a |
Connections |
Load Balance: Select this link to route messages to the next endpoint according to the selected load-balancing strategy. |
Route: Select this link to route all the messages from the sender to the next endpoint. |
|
Limitation |
n/a |
Scenario: Distributing messages to receiver endpoints based on round robin
This scenario applies only to a Talend solution with ESB.
In this scenario, a cLoadBalancer component is used
to distribute four messages evenly to two receiving endpoints in accordance with the
round robin load balancing method.
Dropping and linking the components
This scenario requires one cFile component as the
message sender, one cLoadBalancer component to
distribute the messages to two different receivers in a load balancing manner, two
cJavaDSLProcessor components to define the URIs
of the receivers, two cMessagingEndpoint components
to retrieve the messages routed to the two receivers, and two cProcessor components to display the effect of round robin load
balancing.
-
From the Connectivity folder of the
Palette, drop one cFile component and two cMessagingEndpoint components onto the workspace, and label
them according to their roles in the Route: Sender, Receiver_A, and
Receiver_B respectively. -
From the Routing folder, drop a cLoadBalancer component onto the design
workspace, and label it Load_balancer. -
From the Core folder, drop two cJavaDSLProcessor components onto the design
workspace, and label them according to their roles in the Route: To_Receiver_A and To_Receiver_B respectively. -
From the Custom folder, drop two
cProcessor components onto the design
workspace, and label them according to their roles in the Route: Monitor_A, and Monitor_B respectively. -
Link the cFile component to the cLoadBalancer component using a Row > Route
connection. -
Link cLoadBalancer to each of the two
cJavaDSLProcessor components using a
Row > Load
Balance connection. -
Link each of the two cMessagingEndpoint
components to the corresponding cProcessor
component using a Row > Route connection.
Configuring the components and connections
-
Double-click the cFile component to open
its Basic Settings view in the Component tab. -
In the Path field, specify the file path
to message source. -
From the Encoding list, select the
encoding type of your message files. Leave the other parameters as they
are. -
Double-click the cLoadBalancer component
to open its Basic Settings view in the
Component tab, and select the load
balancing method you want to use from the Strategy list. In this scenario, we use the default
Round robin method. -
Double-click the cJavaDSLProcessor
component labeled To_Receiver_A to open
its Basic Settings view in the Component tab, and enter URI of the first
receiver between the double quotation marks in the Code area,direct:a
in this example.Repeat this step to define the URI of the other receiver,
direct:b
, in the cJavaDSLProcessor component labeled To_Receiver_B. -
Double-click the cMessagingEndpoint
component labeled Receiver_A to open its
Basic Settings view in the Component tab, and enter URI of the first
receiver between the double quotation marks in the URI field,direct:a
in this example.Repeat this step to define the URI of the other receiver,
direct:b
, in the cMessagingEndpoint component labeled Receiver_B. -
Double-click the cProcessor component labeled Monitor_A to open its Basic Settings view in the Component tab, and customize the code in the Code area to display the file names of the
messages routed to Receiver_A on the
console:12System.out.println("Message on Receiver_A: "+exchange.getIn().getHeader("CamelFileName"));Repeat this step to customize the code in the cProcessor component labeled
Monitor_B to display the file names of the messages routed to Receiver_B on the console. - Press Ctrl+S to save your Route.
Viewing the code and executing the Route
-
Click the Code tab at the bottom of the
design workspace to check the generated code:As shown above, while messages are routedfrom
the source endpoint
.to
the destination endpoints, routing load balancing is
implemented according to the.roundRobin()
method by
cLoadBalancer_1
. -
Press F6 to run your Route.
RESULT: Of the four messages from the sender, two are routed to Receiver_A and two are routed to Receiver_B in a round robin manner.