Asterisk
Since Camel 2.18
Both producer and consumer are supported
The Asterisk component allows you to work easily with an Asterisk PBX Server http://www.asterisk.org/ using asterisk-java
This component helps to interface with Asterisk Manager Interface
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-asterisk</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Asterisk component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The Asterisk endpoint is configured using URI syntax:
asterisk:name
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The host name or IP address of the Asterisk server. The consumer and the producer connect to the Asterisk Manager Interface (AMI) of this host on the port of the port option. | String | ||
The port of the Asterisk Manager Interface (AMI) of the Asterisk server, as set in the manager.conf file of the server. | 5038 | int | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
The AMI action that the producer sends for each message: QUEUE_STATUS for the status of the queues and their members, SIP_PEERS for the list of SIP peers, or EXTENSION_STATE for the state of the extension in the CamelAsteriskExtension and CamelAsteriskContext headers. The CamelAsteriskAction header replaces this option for a message. If neither is set, the producer fails the message. Enum values:
| AsteriskAction | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Required The secret of the AMI user, as defined in the manager.conf file of the Asterisk server. | String | ||
Whether to connect to the Asterisk Manager Interface (AMI) over TLS instead of plain TCP, so that the username, the password, the actions and the events are not sent in clear text. The Asterisk server must accept AMI over TLS (tlsenable and tlsbindaddr in the manager.conf file), and the port option must be set to its TLS port, usually 5039, as the default port 5038 is the one of plain TCP. The certificate of the server is checked with the default SSL socket factory and trust store of the JVM (javax.net.ssl.trustStore). The host name of the server is not checked against the certificate, and a custom SSLContext is not supported, as asterisk-java does not offer it. | false | boolean | |
Required The name of the AMI user, as defined in the manager.conf file of the Asterisk server. The consumer and the producer each log in with it when they start. | String |
Message Headers
The Asterisk component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAsteriskEventName (consumer) Constant: | The simple class name of the asterisk-java ManagerEvent in the body, for example NewChannelEvent or HangupEvent. Set by the consumer for each event. | String | |
CamelAsteriskExtension (producer) Constant: | The extension whose state the producer queries with the EXTENSION_STATE action, for example 100. The other actions do not use it. | String | |
CamelAsteriskContext (producer) Constant: | The dialplan context that contains the extension of the CamelAsteriskExtension header, for the EXTENSION_STATE action. The other actions do not use it. | String | |
CamelAsteriskAction (producer) Constant: | The AMI action that the producer sends for this message. Replaces the action option. Enum values:
| AsteriskAction |
Message Body
The message body at each side of the Asterisk component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| The AMI event: a subclass of ManagerEvent such as NewChannelEvent or HangupEvent, with its simple class name in the CamelAsteriskEventName header. The ConnectEvent of the login comes first. |
Producer input |
| The body is not read: the action comes from the action option or the CamelAsteriskAction header, and the extension and context of EXTENSION_STATE from the CamelAsteriskExtension and CamelAsteriskContext headers. |
Producer output |
| QUEUE_STATUS and SIP_PEERS give the ResponseEvents of asterisk-java: the ManagerResponse in getResponse() and the events of the list in getEvents(), such as QueueParamsEvent and QueueMemberEvent or PeerEntryEvent, ending with the complete event. EXTENSION_STATE gives the ManagerResponse, an ExtensionStateResponse. A ManagerError is the response when Asterisk answers with an error.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Action
Supported actions are:
-
QUEUE_STATUS: Queue status
-
SIP_PEERS: List SIP peers
-
EXTENSION_STATE: Check extension status
QUEUE_STATUS and SIP_PEERS are answered with a list of events. The producer waits for the whole list and sets the org.asteriskjava.manager.ResponseEvents as the message body: getResponse() is the response of Asterisk, and getEvents() the events of the list, such as QueueParamsEvent and QueueMemberEvent for QUEUE_STATUS or PeerEntryEvent for SIP_PEERS, ending with the complete event (QueueStatusCompleteEvent or PeerlistCompleteEvent). To route each event on its own, split on ${body.events}.
EXTENSION_STATE sets the ManagerResponse (an ExtensionStateResponse) as the message body. When Asterisk answers with an error, the response is a ManagerError.
TLS
By default the consumer and the producer connect to the Asterisk Manager Interface (AMI) over plain TCP, so the username, the password, the actions and the events are sent in clear text. Set ssl=true to connect over TLS, and set port to the TLS port of the AMI, usually 5039 (the default port 5038 is the one of plain TCP):
from("asterisk:myVoIP?hostname=hostname&port=5039&username=username&password=password&ssl=true")
.log("Received a message - ${body}"); The Asterisk server must accept AMI over TLS on that port: set tlsenable=yes and the tlsbindaddr address (0.0.0.0:5039 for example) in the [general] section of manager.conf, together with the certificate of the server (tlscertfile and tlsprivatekey).
asterisk-java opens the TLS socket with the default SSLSocketFactory of the JVM, so the certificate of the server is checked with the default trust store of the JVM. When the certificate is not signed by a certificate authority that the JVM trusts, add it to a trust store and point the JVM to it with the javax.net.ssl.trustStore and javax.net.ssl.trustStorePassword system properties. A custom SSLContextParameters is not supported, and the host name of the server is not checked against the certificate: asterisk-java offers neither.
Examples
Producer Example
-
Java
-
XML
-
YAML
from("direct:in")
.to("asterisk://myVoIP?hostname=hostname&username=username&password=password&action=EXTENSION_STATE"); <route>
<from uri="direct:in"/>
<to uri="asterisk://myVoIP?hostname=hostname&username=username&password=password&action=EXTENSION_STATE"/>
</route> - route:
from:
uri: direct:in
steps:
- to:
uri: asterisk://myVoIP
parameters:
hostname: hostname
username: username
password: password
action: EXTENSION_STATE Consumer Example
-
Java
-
XML
-
YAML
from("asterisk:myVoIP?hostname=hostname&username=username&password=password")
.log("Received a message - ${body}"); <route>
<from uri="asterisk:myVoIP?hostname=hostname&username=username&password=password"/>
<log message="Received a message - ${body}"/>
</route> - route:
from:
uri: asterisk:myVoIP
parameters:
hostname: hostname
username: username
password: password
steps:
- log:
message: "Received a message - ${body}"