> For the complete documentation index, see [llms.txt](https://prosbcdocs.telcobridges.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://prosbcdocs.telcobridges.com/telecom-references/apis-and-integration/adding-load-sharing-to-a-routing-script.md).

# Adding Load Sharing to a Routing Script

This article show you how to integrate a routing script filter that sorts matching routes by priority and weight (weight is used for load-sharing when multiple routes have the same priority).

Once ordered, the routes will be used, one after the other until a route is working (according to [Route Retry](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/concepts/route-retry/README.md) parameters).

**NOTE: starting from version 3.0.80 this script is installed by default** (only for new installations, or a fresh routing script)

### Setting up Filter Scripts

To setup a Filter, the main script needs to be modified. The main script can be either simple\_routing.rb, or any other script.

First, go to the routing script section of the Web portal

```
Gateway -&gt; Routing scripts -&gt; Example Scripts -&gt; simple_routing.rb [Edit]
```

Three things must be added. At the start of the script:

1.

```
require 'priority_and_weight_load_balancer' unless defined?(PriorityAndWeightLoadBalancer)
```

2.

In the main class:

```
include PriorityAndWeightLoadBalancer
```

3.

```
  after_filter :method => :filter_by_priority_and_weight,
               :weight_by                 => :call_attempts,
               :default_load_share_mode   => :alternate_backup,
               :max_priority_delta        => -1
```

The final script will look like this (with possibly other filters also included):

```
require 'base_routing'
require 'priority_and_weight_load_balancer' unless defined?(PriorityAndWeightLoadBalancer)

class SimpleRouting < BaseRouting
  include PriorityAndWeightLoadBalancer

  route_match :call_field_name => :called
  route_match :call_field_name => :calling
  route_match :call_field_name => :nap
  route_match :method => :match_nap_availability
  route_remap :call_field_name => :called, :route_field_name => :remapped_called
  route_remap :call_field_name => :calling, :route_field_name => :remapped_calling
  route_remap :call_field_name => :nap, :route_field_name => :remapped_nap

  after_filter :method => :filter_by_priority_and_weight,
               :weight_by                 => :call_attempts,
               :default_load_share_mode   => :alternate_backup,
               :max_priority_delta        => -1
end
```

### Adding New Custom Variables

You need to add two custom columns to use this script. There is a default value and it can be changed in each route afterwards.

```
Gateway -&gt; Routes -&gt; Create New Route Column
```

**Name**: priority **Type attributes**: integer **Default**: 10

```
Gateway -&gt; Routes -&gt; Create New Route Column
```

**Name**: weight **Type attributes**: integer **Default**: 100


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://prosbcdocs.telcobridges.com/telecom-references/apis-and-integration/adding-load-sharing-to-a-routing-script.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
