-
-
Save lutzee/9354588cf3d9c24d5843268f028deb58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static class ServiceBusHelperFactory | |
{ | |
internal static IBus CreateReportServiceBus() | |
{ | |
var sb = Bus.Factory.CreateUsingRabbitMq( | |
sbc => | |
{ | |
sbc.UseXmlSerializer(); | |
var host = sbc.Host(new Uri(ConfigHelper.RabbitMqServer), h => | |
{ | |
h.Username(ConfigHelper.RabbitMqUser); | |
h.Password(ConfigHelper.RabbitMqPass); | |
}); | |
sbc.ReceiveEndpoint(host, ConfigHelper.GatewayReportQueue, | |
ep => | |
{ | |
ep.Consumer<ReportConsumer>(); | |
}); | |
ConsoleHelper.WriteLine(ConfigHelper.RabbitMqServer + ConfigHelper.GatewayReportQueue); | |
sbc.UseConcurrencyLimit(1); | |
sbc.UseLog4Net(); | |
sbc.PurgeOnStartup = ConfigHelper.ReportQueuePurgeOnStartup; | |
// override standard of 5 retries. | |
sbc.UseRateLimit(1); | |
}); | |
return sb; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ReportConsumer : | |
GateWayBaseConsumer<ReportRequest, AnyFarmReportRequestMessage, AnyFarmReportStatusMessage, ReportStatusMessage>, | |
IConsumer<ReportRequest>, /*From Web Layer*/ | |
{ | |
private readonly ILog log; | |
public ReportConsumer() | |
{ | |
log = LogManager.GetLogger(typeof(ReportConsumer).FullName); | |
} | |
public Task Consume(ConsumeContext<ReportRequest> context) | |
{ | |
return Task.Run( | |
() => | |
{ | |
try | |
{ | |
DownwardsConsumeMethodTemplate(context); | |
} | |
catch (Exception ex) | |
{ | |
var msg = string.Format("An exception occurred in the consumer. Details {0}", ex.GetInnerMostException()); | |
log.Error(msg); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment