本文整理汇总了C#中IServiceBus.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceBus.Publish方法的具体用法?C# IServiceBus.Publish怎么用?C# IServiceBus.Publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceBus
的用法示例。
在下文中一共展示了IServiceBus.Publish方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WhoisModule
public WhoisModule(IAppSettings appSettings, IServiceBus bus)
{
_bus = bus;
Post["/whois"] = _ =>
{
var slashCommand = this.Bind<SlashCommand>();
if (slashCommand == null ||
slashCommand.command.Missing())
{
Log.Info("Rejected an incoming slash command (unable to parse request body).");
return HttpStatusCode.BadRequest.WithReason("Unable to parse slash command.");
}
if (!appSettings.Get("whois:slackSlashCommandToken").Equals(slashCommand.token))
{
Log.Info("Blocked an unauthorized slash command.");
return HttpStatusCode.Unauthorized.WithReason("Missing or invalid token.");
}
if (!slashCommand.command.Equals("/whois", StringComparison.InvariantCultureIgnoreCase))
{
Log.Info("Rejected an incoming slash command ({0} is not handled by this module).", slashCommand.command);
return HttpStatusCode.BadRequest.WithReason("Unsupported slash command.");
}
var responseText = HandleWhois(slashCommand);
if (responseText.Missing())
{
return HttpStatusCode.OK;
}
return responseText;
};
Post["/whois/fullcontact/person"] = _ =>
{
// Parse the request data
var person = this.BindTo(new FullContactPersonResult());
if (person == null ||
person.Result == null)
{
Log.Info("Rejected webhook call from FullContact (unable to parse request body).");
return HttpStatusCode.BadRequest.WithReason("Unable to parse request body.");
}
// Get the pending command that corresponds to the posted data
if (string.IsNullOrWhiteSpace(person.WebhookId))
{
Log.Info("Rejected a webhook call from FullContact (webhookId missing).");
return HttpStatusCode.BadRequest.WithReason("The webhookId property is missing from the request body.");
}
bus.Publish(person);
return HttpStatusCode.OK;
};
}
示例2: PublishingThread
private static void PublishingThread(IServiceBus bus)
{
while (true)
{
var guid = Guid.NewGuid();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Publishing event with guid " + guid);
bus.Publish(new SomethingHappenedEvent { Guid = guid, Sent = DateTime.Now });
Thread.Sleep(1000);
}
}
示例3: Subscribing_a_consumer_to_the_bus
public void Subscribing_a_consumer_to_the_bus()
{
_bus = ServiceBusFactory.New(x =>
{
x.ReceiveFrom("loopback://localhost/mt_test");
x.Subscribe(s => s.Consumer(typeof (ConsumerOf<PingMessage>), Activator.CreateInstance));
});
_ping = new PingMessage(Guid.NewGuid());
_bus.Publish(_ping);
}
示例4: Subscribing_a_consumer_to_the_bus
public void Subscribing_a_consumer_to_the_bus()
{
_bus = ServiceBusFactory.New(x =>
{
x.ReceiveFrom("loopback://localhost/mt_test");
x.Subscribe(s => s.Consumer<ConsumerOf<PingMessage>>());
});
_ping = new PingMessage();
_bus.Publish(_ping);
}
示例5: MailgunModule
public MailgunModule(
IServiceBus bus,
IMailgunWebhooks mailgunWebhooks)
{
Post["/webhooks/mailgun/{webhookId}/{slackChannel}"] = _ =>
{
Log.Debug("Received webhook call from Mailgun.");
// TODO Verify signature?
var webhookId = (string)_.webhookId;
if (webhookId.Missing())
{
Log.Info("Rejected webhook call from Mailgun (WebhookId is missing).");
return HttpStatusCode.NotAcceptable.WithReason("WebhookId is missing.");
}
var webhook = mailgunWebhooks.Get(webhookId);
if (webhook == null)
{
Log.Info("Rejected webhook call from Mailgun (webhook '{0}' not found).", webhookId);
return HttpStatusCode.NotAcceptable.WithReason("The webhook does not exist.");
}
var slackChannel = "#" + ((string)_.slackChannel).TrimStart('#');
var sender = (string)Request.Form["sender"];
var recipient = (string)Request.Form["recipient"];
var subject = (string)Request.Form["subject"];
var plainBody = (string)Request.Form["body-plain"];
// HACK: Since Nancy parses subject into "subject,subject", just split in two for now
subject = subject.Substring(0, subject.Length/2);
// Send notification to Slack.
bus.Publish(new MessageToSlack
{
channel = slackChannel,
text = string.Format("E-mail from *{0}*:\n", sender, recipient),
attachments = new[]
{
new MessageToSlack.Attachment
{
fallback = string.Format("*{0}*", subject),
pretext = string.Format("*{0}*", subject),
text = string.Format("{0}", plainBody),
mrkdwn_in = new [] { "fallback", "pretext" }
}
}
});
return HttpStatusCode.OK;
};
}
示例6: Subscribing_an_object_instance_to_the_bus
public void Subscribing_an_object_instance_to_the_bus()
{
_consumer = new ConsumerOf<PingMessage>();
object instance = _consumer;
_bus = ServiceBusFactory.New(x =>
{
x.ReceiveFrom("loopback://localhost/mt_test");
x.Subscribe(s => s.Instance(instance));
});
_ping = new PingMessage();
_bus.Publish(_ping);
}
示例7: Main
private static void Main(string[] args)
{
_bus = ServiceBusFactory.New(sbc =>
{
sbc.UseRabbitMqRouting();
sbc.ReceiveFrom("rabbitmq://localhost/matt1");
sbc.UseJsonSerializer();
sbc.Subscribe(s => s.Handler<Response>(HandleMessage));
});
var id = 0;
while (true)
{
_bus.Publish(new Request {CorrelationId = id, Text = "Hiiiii"});
Console.Out.WriteLine("Published request " + id);
id++;
Thread.Sleep(5000);
}
}
示例8: Start
public void Start(IServiceBus bus)
{
_bus = bus;
_bus.SubscribeConsumer<PasswordUpdater>();
Console.WriteLine(new string('-', 20));
Console.WriteLine("New Password Client");
Console.WriteLine("What would you like to set your new password to?");
Console.Write("New Password:");
string newPassword = Console.ReadLine();
Console.WriteLine(new string('-', 20));
var message = new RequestPasswordUpdate(newPassword);
_bus.Publish(message);
Console.WriteLine("Waiting For Reply with CorrelationId '{0}'", message.CorrelationId);
Console.WriteLine(new string('-', 20));
}
示例9: Main
static void Main(string[] args)
{
StartSubscriptionService();
using (_bus = ServiceBusFactory.New(sbc =>
{
sbc.UseStomp();
sbc.ReceiveFrom(string.Format("{0}/queue/matt2", Constants.HostUri));
sbc.UseSubscriptionService("{0}/queue/matt_subscriptions".FormatWith(Constants.HostUri));
sbc.UseControlBus();
sbc.Subscribe(s => s.Handler<Response>(HandleMessage));
}))
{
var id = 0;
while (true)
{
_bus.Publish(new Request { CorrelationId = id, Text = "Hiiiii" });
Console.Out.WriteLine("Published request " + id);
id++;
Thread.Sleep(5000);
}
}
}
示例10: Subscribing_a_conditional_handler_to_a_bus
public void Subscribing_a_conditional_handler_to_a_bus()
{
_received = new Future<PingMessage>();
_conditionChecked = new Future<PingMessage>();
_bus = ServiceBusFactory.New(x =>
{
x.ReceiveFrom("loopback://localhost/mt_test");
x.Subscribe(s =>
{
// a simple handler
s.Handler<PingMessage>(msg => _received.Complete(msg))
.Where(msg =>
{
_conditionChecked.Complete(msg);
return true;
});
});
});
_bus.Publish(new PingMessage());
}
示例11: Setup
public void Setup()
{
this.eventstore = Wireup.Init()
.UsingInMemoryPersistence()
.UsingSynchronousDispatchScheduler()
.DispatchTo(new DelegateMessageDispatcher(c =>
{
c.Events.ForEach(dispatchedEvents.Add);
c.Events.Select(m=>m.Body).ToList().ForEach(bus.Publish);
}))
.Build();
var aggregateRepository = new EventStoreRepository(
eventstore
, new AggregateFactory()
,new ConflictDetector());
var updateStorage = new InMemoryDbUpdateStorage();
this.readStorage = updateStorage;
this.bus = ServiceBusFactory.New(sbc =>
{
sbc.ReceiveFrom("loopback://localhost/test");
sbc.Subscribe(x => x.Consumer(() => new ManagerCommandHandler(aggregateRepository)));
sbc.Subscribe(x => x.Consumer(() => new ManagerInfoDenormalizer(updateStorage)));
});
var createManagerCommand = new CreateManager(managerId, "Max", "Cole");
bus.Publish(createManagerCommand);
TaskManager taskManager = new TaskManager(TimeSpan.FromMilliseconds(500));
taskManager.
When(() => this.readStorage.Items<ManagerInfo>().Any()).
Then(()=>this.sync.Set());
this.sync.WaitOne(TimeSpan.FromSeconds(5));
}
示例12: DoTest
static void DoTest(IServiceBus publishingBus, IServiceBus receivingBus)
{
int numberOfFailures = new Random().Next(5) + 1;
int receiveCount = 0;
Guid testId = Guid.NewGuid();
Trace.WriteLine(string.Format("Number of failures for message: {0}", numberOfFailures));
using (var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset))
{
receivingBus.SubscribeContextHandler<Message>(context =>
{
try
{
Message message = context.Message;
// ignore messages from older tests
if (message.TestId != testId)
return;
Trace.Write("Processing message...", "Handler");
receiveCount++;
// retry as many times as requested by message
if (context.RetryCount < message.NumberOfFailures)
{
Trace.WriteLine(string.Format("Message will be retried (retry count = {0}).",
context.RetryCount));
context.RetryLater();
}
else
{
Trace.WriteLine("Message processed.");
waitHandle.Set();
}
}
catch (Exception exc)
{
Trace.WriteLine(exc, "Handler failed");
throw;
}
});
publishingBus.Publish(new Message {NumberOfFailures = numberOfFailures, TestId = testId});
Assert.True(waitHandle.WaitOne(Debugger.IsAttached
? TimeSpan.FromHours(1)
: TimeSpan.FromSeconds(10)));
}
Assert.AreEqual(numberOfFailures + 1, receiveCount);
}
示例13: Subscribing_a_context_handler_to_a_bus
public void Subscribing_a_context_handler_to_a_bus()
{
_received = new Future<PingMessage>();
_bus = ServiceBusFactory.New(x =>
{
x.ReceiveFrom("loopback://localhost/mt_test");
x.Subscribe(s =>
{
// a simple handler
s.Handler<PingMessage>((context,message) =>_received.Complete(message));
});
});
_bus.Publish(new PingMessage());
}