本文整理汇总了C#中IBus.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# IBus.Publish方法的具体用法?C# IBus.Publish怎么用?C# IBus.Publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBus
的用法示例。
在下文中一共展示了IBus.Publish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run(IBus bus, TextWriter w)
{
_c.Add(bus.Subscribe<MessageA>(OnMessageA));
_c.Add(bus.Subscribe<MessageB>(OnMessageB));
_c.Add(bus.Subscribe<MessageC>(OnMessageC));
var r = new Random();
var dict = new Dictionary<int, Func<object>>
{
{0, () => new MessageA()},
{1, () => new MessageB()},
{2, () => new MessageC()},
};
int count = 0;
var sw = Stopwatch.StartNew();
while (count < 100000)
{
bus.Publish(dict[r.Next(0, 3)]());
count++;
}
w.WriteLine("Through {0}", sw.ElapsedMilliseconds);
while (_aCount != MessageA.Count && _bCount != MessageB.Count && _cCount != MessageC.Count)
{
WriteInfo(w);
Thread.Sleep(1000);
}
WriteInfo(w);
}
示例2: Run
public void Run(IBus bus, TextWriter w)
{
c.Add(bus.Subscribe<MessageA>(onMessageA));
c.Add(bus.Subscribe<MessageB>(onMessageB));
c.Add(bus.Subscribe<MessageC>(onMessageC));
var r = new Random();
var dict = new Dictionary<int, Func<object>>
{
{0, () => new MessageA()},
{1, () => new MessageB()},
{2, () => new MessageC()},
};
int count = 0;
var sw = Stopwatch.StartNew();
while (count < 100000)
{
bus.Publish(dict[r.Next(0, 3)]());
count++;
}
w.WriteLine("Through {0}", sw.ElapsedMilliseconds);
count = 0;
while (count < 10)
{
w.WriteLine("From MsgA:{0}({1}), B:{2}({3}), C:{4}({5})", aCount, MessageA.Count, bCount,
MessageB.Count, cCount, MessageC.Count);
Thread.Sleep(1000);
count++;
}
}
示例3: Start
static void Start(IBus bus)
{
Console.WriteLine("This will publish IEvent, EventMessage, and AnotherEventMessage alternately.");
Console.WriteLine("Press 'Enter' to publish a message.To exit, Ctrl + C");
var nextEventToPublish = 0;
while (Console.ReadLine() != null)
{
var eventId = Guid.NewGuid();
switch (nextEventToPublish)
{
case 0:
bus.Publish<IMyEvent>(m =>
{
m.EventId = eventId;
m.Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null;
m.Duration = TimeSpan.FromSeconds(99999D);
});
nextEventToPublish = 1;
break;
case 1:
var eventMessage = new EventMessage
{
EventId = eventId,
Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
Duration = TimeSpan.FromSeconds(99999D)
};
bus.Publish(eventMessage);
nextEventToPublish = 2;
break;
default:
var anotherEventMessage = new AnotherEventMessage
{
EventId = eventId,
Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
Duration = TimeSpan.FromSeconds(99999D)
};
bus.Publish(anotherEventMessage);
nextEventToPublish = 0;
break;
}
Console.WriteLine("Published event with Id {0}.", eventId);
Console.WriteLine("==========================================================================");
}
}
示例4: SendMessages
public override IEnumerable<Task> SendMessages(IBus bus)
{
for (var i = 0; i < NumMessagesToSend/8; i++)
{
yield return bus.Publish(new FooEvent());
yield return bus.Publish(new BarEvent());
yield return bus.Publish(new BazEvent());
yield return bus.Publish(new QuxEvent());
Console.Write(".");
}
Console.WriteLine();
}
示例5: Start
static void Start(IBus bus)
{
Console.WriteLine("Press '1' to publish IEvent");
Console.WriteLine("Press '2' to publish EventMessage");
Console.WriteLine("Press '3' to publish AnotherEventMessage");
Console.WriteLine("Press any other key to exit");
#region PublishLoop
while (true)
{
ConsoleKeyInfo key = Console.ReadKey();
Console.WriteLine();
Guid eventId = Guid.NewGuid();
switch (key.Key)
{
case ConsoleKey.D1:
bus.Publish<IMyEvent>(m =>
{
m.EventId = eventId;
m.Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null;
m.Duration = TimeSpan.FromSeconds(99999D);
});
Console.WriteLine("Published IMyEvent with Id {0}.", eventId);
continue;
case ConsoleKey.D2:
EventMessage eventMessage = new EventMessage
{
EventId = eventId,
Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null,
Duration = TimeSpan.FromSeconds(99999D)
};
bus.Publish(eventMessage);
Console.WriteLine("Published EventMessage with Id {0}.", eventId);
continue;
case ConsoleKey.D3:
AnotherEventMessage anotherEventMessage = new AnotherEventMessage
{
EventId = eventId,
Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null,
Duration = TimeSpan.FromSeconds(99999D)
};
bus.Publish(anotherEventMessage);
Console.WriteLine("Published AnotherEventMessage with Id {0}.", eventId);
continue;
default:
return;
}
}
#endregion
}
示例6: PlaceNewOrder
private static void PlaceNewOrder(IBus bus)
{
var meal = Meals[Random.Next(0, 2)];
var size = Sizes[Random.Next(0, 3)];
bus.Publish(new NewOrderMessage(Guid.NewGuid()) { Name = meal, Size = size });
}
示例7: ConcreteMessage
void ConcreteMessage(IBus bus)
{
#region InstancePublish
MyEvent message = new MyEvent { SomeProperty = "Hello world" };
bus.Publish(message);
#endregion
}
示例8: Start
static void Start(IBus bus)
{
Console.WriteLine("Press 'p' to Publish MyEvent");
Console.WriteLine("Press 's' to SendLocal MyMessage");
Console.WriteLine("Press any other key to exit");
while (true)
{
var key = Console.ReadKey();
Console.WriteLine();
var id = Guid.NewGuid();
if (key.Key == ConsoleKey.P)
{
var myEvent = new MyEvent
{
Id = id,
};
bus.Publish(myEvent);
Console.WriteLine("Published MyEvent with Id {0}.", id);
continue;
}
if (key.Key == ConsoleKey.S)
{
var eventMessage = new MyMessage
{
Id = id,
};
bus.SendLocal(eventMessage);
Console.WriteLine("Sent MyMessage with Id {0}.", id);
continue;
}
return;
}
}
示例9: InterfaceMessage
void InterfaceMessage(IBus bus)
{
#region InterfacePublish
bus.Publish<IMyEvent>(m => { m.SomeProperty = "Hello world"; });
#endregion
}
示例10: ReplayCommandModule
public ReplayCommandModule(IBus bus)
{
Get["/Replay"] = parameters =>
{
bus.Publish(new ReplayCommand());
return Response.AsJson("Done!");
};
}
示例11: SendMessages
public override async Task SendMessages(IBus bus, Func<bool> shouldKeepSending)
{
while (shouldKeepSending())
{
await bus.Publish(new FooEvent());
IncrementExpectedMessageCount(2);
}
}
示例12: Publish
public static void Publish(IBus bus)
{
foreach (var word in WordLoader.LoadWords())
{
Thread.Sleep(10);
bus.Publish(new WordMessage{ Word = word });
Console.WriteLine("Published '{0}'", word);
}
}
示例13: PublishEvent
static void PublishEvent(IBus bus)
{
Guid eventId = Guid.NewGuid();
bus.Publish<IMyEvent>(m =>
{
m.EventId = eventId;
});
Console.WriteLine("Event published, id: " + eventId);
}
示例14: Publish
static void Publish(int numberOfJobs, IBus bus)
{
Console.WriteLine("Publishing {0} jobs", numberOfJobs);
var jobs = Enumerable.Range(0, numberOfJobs)
.Select(i => new Job { JobNumber = i })
.Select(job => bus.Publish(job))
.ToArray();
Task.WaitAll(jobs);
}
示例15: Initialize
public void Initialize(IBus bus)
{
bus.Subscribe<StartMessage>("id", startMessage =>
{
var request = new TestRequestMessage {Text = startMessage.Text};
bus.Request<TestRequestMessage, TestResponseMessage>(request, response =>
{
var endMessage = new EndMessage {Text = response.Text};
bus.Publish(endMessage);
});
});
}