Configuring HareDu
Configuring HareDu depends on how you want to use it in your application. But fear not, its pretty simple as you will see.
Required Parameters
Step 1: Call the static method, Initialize, from HareDuClient
HareDuFactory client = HareDuClient.Initialize(x =>
{
...
});
Step 2: Call the ConnectTo method and enter your URL to the RabbitMQ cluster
x.ConnectTo(<url>:<port>);
Step 3: Enter the RabbitMQ user credentials
x.UsingCredentials(<username>, <password>);
Optional Parameters
Logging
Logging is very important
Step 1: Enable logging by calling the Enable method.
x.Logging(l =>
{
l.Enable();
...
});
Step 2: Chose which logger will be used by calling the UseLogger method
x.Logging(l =>
{
...
l.UseLogger(<logger>);
});
Step 3: Create a file called log4net.config in your project and ensure that the "Copy to output directory" property is set to either "Copy if newer" or "Copy always". Fill free to change the configuration as you see fit.
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
</root>
<logger name="HareDuLogger">
<level value="INFO" />
<appender-ref ref="LogFile" />
</logger>
<appender name="LogFile" type="log4net.Appender.RollingFileAppender">
<file value="HareDu-" />
<appendToFile value="true" />
<datePattern value="yyyyMMdd.log" />
<rollingStyle value="Date" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100MB" />
<param name="StaticLogFileName" value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{yyyy-MM-dd hh:mm:ss.fff} %-5level [%thread] %m%n" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
<mapping>
<level value="ERROR" />
<foreColor value="Red, HighIntensity" />
</mapping>
<mapping>
<level value="WARN" />
<foreColor value="Yellow, HighIntensity" />
</mapping>
<mapping>
<level value="INFO" />
<foreColor value="White" />
</mapping>
<mapping>
<level value="DEBUG" />
<foreColor value="Cyan" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger %ndc - %message%newline" />
</layout>
</appender>
</log4net>
For more information on logging with log4net please go to the following link.
Putting it altogether
Putting it altogether your client should look like this...
HareDuFactory client = HareDuClient.Initialize(x =>
{
x.ConnectTo(<url>:<port>);
x.Logging(l =>
{
l.Enable();
l.UseLogger(<logger>);
});
x.UsingCredentials(<username>, <password>);
});
Alternatives
There is more than one way to configure a HareDu client. The above code snippet represents a basic usage scenario for which you have the ability upfront to initialize the client from information on hand. However, there are plenty times where you will not have, say, unencrypted user credentials to plug in and you will need to pull configuration from somewhere else. In such a scenario you have a couple options:
JSON configuration
The configuration string that the client takes is JSON and has the below schema.
{
"rmqServerUrl":"<string>",
"timeout":"<datetime>",
"logger":{
"enable":<boolean>,
"name":"<string>"
},
"credentials":{
"username":"<string>",
"password":"<string>"
}
}
*Please note that the order in which you call the methods has no bearing on how the client is initialized.