[[IRC-IRCComponent]]
IRC Component
~~~~~~~~~~~~~

The *irc* component implements an
http://en.wikipedia.org/wiki/Internet_Relay_Chat[IRC] (Internet Relay
Chat) transport.

Maven users will need to add the following dependency to their `pom.xml`
for this component:

[source,xml]
------------------------------------------------------------
<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>
------------------------------------------------------------

[[IRC-URIformat]]
URI format
^^^^^^^^^^

[source,java]
---------------------------------------------------------------------
irc:nick@host[:port]/#room[?options]
irc:nick@host[:port]?channels=#channel1,#channel2,#channel3[?options]
---------------------------------------------------------------------

You can append query options to the URI in the following format,
`?option=value&option=value&...`

[[IRC-Options]]
Options
^^^^^^^


// component options: START
The IRC component has no options.
// component options: END







// endpoint options: START
The IRC component supports 26 endpoint options which are listed below:

{% raw %}
[width="100%",cols="2,1,1m,1m,5",options="header"]
|=======================================================================
| Name | Group | Default | Java Type | Description
| hostname | common |  | String | *Required* Hostname for the IRC chat server
| port | common | 6667,6668,6669 | int | Port number for the IRC chat server
| autoRejoin | common | true | boolean | Whether to auto re-join when being kicked
| namesOnJoin | common | false | boolean | Sends NAMES command to channel after joining it. link onReply has to be true in order to process the result which will have the header value irc.num = '353'.
| nickname | common |  | String | The nickname used in chat.
| persistent | common | true | boolean | Use persistent messages.
| realname | common |  | String | The IRC user's actual name.
| bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored.
| exceptionHandler | consumer (advanced) |  | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.
| exchangePattern | consumer (advanced) |  | ExchangePattern | Sets the exchange pattern when the consumer creates an exchange.
| colors | advanced | true | boolean | Whether or not the server supports color codes.
| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
| onJoin | filter | true | boolean | Handle user join events.
| onKick | filter | true | boolean | Handle kick events.
| onMode | filter | true | boolean | Handle mode change events.
| onNick | filter | true | boolean | Handle nickname change events.
| onPart | filter | true | boolean | Handle user part events.
| onPrivmsg | filter | true | boolean | Handle private message events.
| onQuit | filter | true | boolean | Handle user quit events.
| onReply | filter | false | boolean | Whether or not to handle general responses to commands or informational messages.
| onTopic | filter | true | boolean | Handle topic change events.
| nickPassword | security |  | String | Your IRC server nickname password.
| password | security |  | String | The IRC server password.
| sslContextParameters | security |  | SSLContextParameters | Used for configuring security using SSL. Reference to a org.apache.camel.util.jsse.SSLContextParameters in the Registry. This reference overrides any configured SSLContextParameters at the component level. Note that this setting overrides the trustManager option.
| trustManager | security |  | SSLTrustManager | The trust manager used to verify the SSL server's certificate.
| username | security |  | String | The IRC server user name.
|=======================================================================
{% endraw %}
// endpoint options: END






[[IRC-SSLSupport]]
SSL Support
^^^^^^^^^^^

[[IRC-UsingtheJSSEConfigurationUtility]]
Using the JSSE Configuration Utility
++++++++++++++++++++++++++++++++++++

As of Camel 2.9, the IRC component supports SSL/TLS configuration
through the link:camel-configuration-utilities.html[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.

[[IRC-Programmaticconfigurationoftheendpoint]]
Programmatic configuration of the endpoint

[source,java]
-----------------------------------------------------------------------------------------------------------------------------------------
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");
-----------------------------------------------------------------------------------------------------------------------------------------

[[IRC-SpringDSLbasedconfigurationofendpoint]]
Spring DSL based configuration of endpoint

[source,xml]
----------------------------------------------------------------------------------------------------------------------------------------------
...
  <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"/>...
----------------------------------------------------------------------------------------------------------------------------------------------

[[IRC-Usingthelegacybasicconfigurationoptions]]
Using the legacy basic configuration options
++++++++++++++++++++++++++++++++++++++++++++

You can also connect to an SSL enabled IRC server, as follows:

[source,java]
--------------------------------------------------
ircs:host[:port]/#room?username=user&password=pass
--------------------------------------------------

By default, the IRC transport uses
http://moepii.sourceforge.net/irclib/javadoc/org/schwering/irc/lib/ssl/SSLDefaultTrustManager.html[SSLDefaultTrustManager].
If you need to provide your own custom trust manager, use the
`trustManager` parameter as follows:

[source,java]
----------------------------------------------------------------------------------------------
ircs:host[:port]/#room?username=user&password=pass&trustManager=#referenceToMyTrustManagerBean
----------------------------------------------------------------------------------------------

[[IRC-Usingkeys]]
Using keys
^^^^^^^^^^

*Available as of Camel 2.2*

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.

[source,java]
-----------------------------------------------------------------------------
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:

[source,java]
-----------------------------------------------------------------------------
from("ircs:nick@myserver:1234/#mychannelname?listOnJoin=true&onReply=true")
	.choice()
		.when(header("irc.messageType").isEqualToIgnoreCase("REPLY"))
			.filter(header("irc.num").isEqualTo("353"))
			.to("mock:result").stop();
-----------------------------------------------------------------------------

[[IRC-SeeAlso]]
See Also
^^^^^^^^

* link:configuring-camel.html[Configuring Camel]
* link:component.html[Component]
* link:endpoint.html[Endpoint]
* link:getting-started.html[Getting Started]

