IRC
Since Camel 1.1
Both producer and consumer are supported
The IRC component implements an IRC (Internet Relay Chat) transport.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-irc</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
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. 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.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
Configuring Endpoint Options
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for 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, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
Component Options
The IRC component supports 4 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 |
|
Enable usage of global SSL context parameters. |
false |
boolean |
Endpoint Options
The IRC endpoint is configured using URI syntax:
irc:hostname:port
with the following path and query parameters:
Path Parameters (2 parameters)
Name | Description | Default | Type |
---|---|---|---|
Required Hostname for the IRC chat server. |
String |
||
Port number for the IRC chat server. If no port is configured then a default port of either 6667, 6668 or 6669 is used. |
int |
Query Parameters (27 parameters)
Name | Description | Default | Type |
---|---|---|---|
Whether to auto re-join when being kicked. |
true |
boolean |
|
Comma separated list of IRC channels. |
String |
||
Delay in milliseconds before sending commands after the connection is established. |
5000 |
long |
|
Comma separated list of keys for channels. |
String |
||
Sends NAMES command to channel after joining it. onReply has to be true in order to process the result which will have the header value irc.num = '353'. |
false |
boolean |
|
The nickname used in chat. |
String |
||
Deprecated Use persistent messages. |
true |
boolean |
|
The IRC user’s actual name. |
String |
||
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 |
||
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 or not the server supports color codes. |
true |
boolean |
|
Handle user join events. |
true |
boolean |
|
Handle kick events. |
true |
boolean |
|
Handle mode change events. |
true |
boolean |
|
Handle nickname change events. |
true |
boolean |
|
Handle user part events. |
true |
boolean |
|
Handle private message events. |
true |
boolean |
|
Handle user quit events. |
true |
boolean |
|
Whether or not to handle general responses to commands or informational messages. |
false |
boolean |
|
Handle topic change events. |
true |
boolean |
|
Your IRC server nickname password. |
String |
||
The IRC server password. |
String |
||
Used for configuring security using SSL. Reference to a org.apache.camel.support.jsse.SSLContextParameters in the Registry. This reference overrides any configured SSLContextParameters at the component level. Note that this setting overrides the trustManager option. |
SSLContextParameters |
||
The trust manager used to verify the SSL server’s certificate. |
SSLTrustManager |
||
The IRC server user name. |
String |
Message Headers
The IRC component supports 10 message header(s), which is/are listed below:
Name | Description | Default | Type |
---|---|---|---|
Constant: |
The type of message. |
String |
|
Constant: |
The target. |
String |
|
Constant: |
The nickname or channel the message should be sent to. |
String |
|
Constant: |
The nickname of the user who is kicked from a channel (passive). |
String |
|
Constant: |
The host of the person who sent the line. |
String |
|
Constant: |
The nickname of the person who sent the line or the server name of the server which sent the line. |
String |
|
Constant: |
The server name of the server which sent the line or the nickname of the person who sent the line. |
String |
|
Constant: |
The username of the person who sent the line. |
String |
|
Constant: |
The numeric reply. |
int |
|
Constant: |
The first part of the message. |
String |
SSL Support
Using the JSSE Configuration Utility
The IRC component supports SSL/TLS configuration through the Camel JSSE Configuration Utility. This utility greatly decreases the amount of component specific code you need to write and is configurable at the endpoint and component levels. The following examples demonstrate how to use the utility with the IRC component.
Programmatic configuration of the endpoint
KeyStoreParameters ksp = new KeyStoreParameters();
ksp.setResource("/users/home/server/truststore.jks");
ksp.setPassword("keystorePassword");
TrustManagersParameters tmp = new TrustManagersParameters();
tmp.setKeyStore(ksp);
SSLContextParameters scp = new SSLContextParameters();
scp.setTrustManagers(tmp);
Registry registry = ...
registry.bind("sslContextParameters", scp);
...
from(...)
.to("ircs://camel-prd-user@server:6669/#camel-test?nickname=camel-prd&password=password&sslContextParameters=#sslContextParameters");
Spring DSL based configuration of endpoint
...
<camel:sslContextParameters
id="sslContextParameters">
<camel:trustManagers>
<camel:keyStore
resource="/users/home/server/truststore.jks"
password="keystorePassword"/>
</camel:keyManagers>
</camel:sslContextParameters>...
...
<to uri="ircs://camel-prd-user@server:6669/#camel-test?nickname=camel-prd&password=password&sslContextParameters=#sslContextParameters"/>...
Using the legacy basic configuration options
You can also connect to an SSL enabled IRC server, as follows:
ircs:host[:port]/#room?username=user&password=pass
By default, the IRC transport uses
SSLDefaultTrustManager.
If you need to provide your own custom trust manager, use the
trustManager
parameter as follows:
ircs:host[:port]/#room?username=user&password=pass&trustManager=#referenceToMyTrustManagerBean
Using keys
Some irc rooms requires you to provide a key to be able to join that channel. The key is just a secret word.
For example we join 3 channels where as only channel 1 and 3 uses a key.
irc:nick@irc.server.org?channels=#chan1,#chan2,#chan3&keys=chan1Key,,chan3key
Getting a list of users of the channel
Using the namesOnJoin
option one can invoke the IRC-NAMES
command after the component has joined a channel.
The server will reply with irc.num = 353
. So in order to process the result the property onReply
has to be true
.
Furthermore one has to filter the onReply
exchanges in order to get the names.
For example we want to get all exchanges that contain the usernames of the channel:
from("ircs:nick@myserver:1234/#mychannelname?namesOnJoin=true&onReply=true")
.choice()
.when(header("irc.messageType").isEqualToIgnoreCase("REPLY"))
.filter(header("irc.num").isEqualTo("353"))
.to("mock:result").stop();
Sending to different channel or a person
If you need to send messages to a different channel (or a person) which is not defined on IRC endpoint, you can specify a different destination in a message header.
You can specify the destination in the following header:
Header | Type | Description |
---|---|---|
|
|
The channel (or the person) name. |