public void Publish() { var message = new ExampleMessage { Greeting = "Hello, world!" }; using (var channel = bus.OpenPublishChannel()) channel.Publish(message); }
public void HandleMessage(ExampleMessage exampleMessage) { var toSerialize = new ProtoTestMessage() {MessageBody = exampleMessage.BodyText}; var testFile = File.Create(Directory.GetCurrentDirectory() + "\\BlackBook.txt"); Serializer.Serialize(testFile, toSerialize); testFile.Close(); }
public static void Main(string[] args) { Console.WriteLine("Server launch"); var client = new Client("localhost", 1337); // Attaching a handler client.Dispatcher.AttachHandler(typeof(ExampleMessage), new ExampleClientHandler(client)); client.Run(); // To write some commands while (true) { var line = Console.ReadLine(); switch (line) { default: var m = new ExampleMessage { Content = line }; client.Send(m); Console.WriteLine($"Message '{line}' sent!"); break; } } }
public IEnumerable <ExampleMessage> Get() { Thread.Sleep(5000); // intentional delay to simulate a longer process to crunch data. This can be removed. var userEmailClaim = HttpContext?.User?.Claims?.FirstOrDefault(p => p.Type == @"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"); string email = userEmailClaim?.Value ?? "Unknown email"; var firstMsgToSend = new ExampleMessage { MsgType = "AdminMsg", StringData = $"Cookies says your email is '{email}'.", DateOrTime = DateTime.Now, IntData = 0, }; string[] RandomStringDataToSend = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; var rng = new Random(); return((new ExampleMessage[] { firstMsgToSend }.Concat(Enumerable.Range(1, 5).Select(index => new ExampleMessage { MsgType = "Msg-type", StringData = RandomStringDataToSend[rng.Next(RandomStringDataToSend.Length)], DateOrTime = DateTime.Now.AddDays(index), IntData = rng.Next(-20, 55) }))).ToArray()); }
static void SendOrder(IEndpointInstance endpointInstance) { Console.WriteLine("Press enter to send a message"); Console.WriteLine("Press any key to exit"); while (true) { var key = Console.ReadKey(); Console.WriteLine(); if (key.Key != ConsoleKey.Enter) { return; } var exampleMessage = new ExampleMessage { Id = Guid.NewGuid() }; endpointInstance.Send("example.server", exampleMessage); Console.WriteLine($"Sent a message with id: {exampleMessage.Id:N}"); } }
void Start() { Logger.text = string.Empty; Debug.Log("Starting Messaging Test"); Counts = 0; var m = new ExampleMessage(); var m2 = new CachedExampleMessage(); Messenger.Subscribe(this); Messenger.Publish(m); Assert(() => Counts == 2, "Sub Then Pub"); Messenger.Unsubscribe(this); Messenger.Publish(m2); Messenger.Subscribe(this); Messenger.ClearCache(); Assert(() => Counts == 3, "Cached Sub / Pub"); Messenger.Unsubscribe(this); Messenger <object> .Subscribe(ObjectHandler); Messenger.Publish(m); Messenger.Publish(m2); Assert(() => Counts == 5, "Manual Sub / Pub"); Debug.Log("All Done"); }
public void ExampleSendMessage() { //Construct the message. ExampleMessage msg = new ExampleMessage(1, "ExampleData"); //Send the message. client.SendMessageReliable(msg); }
public void ResponseBadAuthentication(Server server, Client client) { // Logic when client is trying to cheat... var message = new ExampleMessage { Content = "You tried to send a packet without authentication." }; //todo: send to client }
public static void HandleMessageForLoadedPlugins(ExampleMessage message) { foreach (var loadedPluginEntry in LoadedPlugins.Keys) { var plugin = GetPluginInstance(loadedPluginEntry); plugin.HandleMessage(message); //Could async this if needed } }
public static void HandleMessageForLoadedPlugins(ExampleMessage message) { foreach (var loadedPluginEntry in LoadedPlugins.Keys) { var plugin = GetPluginInstance(loadedPluginEntry); plugin.HandleMessage(message); //Could async this if needed } }
public void Publish() { var message = new ExampleMessage { Greeting = "Hello, world!" }; using (var channel = bus.OpenPublishChannel()) channel.Publish(message); }
private static void HandleReceiveMessage(ExampleMessage msg) { Log("Received: " + msg.Test); if (FordwardingQueue != null) { Log("Forwarding to " + FordwardingQueue); bus.Send(FordwardingQueue, msg); } }
public static void Run() { ISubscribe <ExampleMessage> queue = Configuration.GetQueue <ExampleMessage>(); while (true) { Reset.WaitOne(); ExampleMessage message = queue.Receive(); Interlocked.Increment(ref _readCount); } }
public async Task Send(string text) { var message = new ExampleMessage() { Text = text }; using var sender = _factory.CreateMessageSender <ExampleMessage>(queueId); await sender.SendMessageAsync(message); }
public void HandleMessage(ExampleMessage exampleMessage) { var toSerialize = new ProtoTestMessage() { MessageBody = exampleMessage.BodyText }; var testFile = File.Create(Directory.GetCurrentDirectory() + "\\BlackBook.txt"); Serializer.Serialize(testFile, toSerialize); testFile.Close(); }
public void HandleMessage(ExampleMessage exampleMessage) { var directionRequest = new DirectionsRequest() { Origin = "607 clear spring ln. leander tx 78641", Destination = exampleMessage.BodyText //TODO: JSON Deserialization? Common message format? Unsure here }; var directions = GoogleMapsApi.GoogleMaps.Directions.Query(directionRequest); var testFile = File.CreateText(Directory.GetCurrentDirectory() + "\\Kbb.txt"); foreach (var step in directions?.Routes?.FirstOrDefault()?.Legs?.FirstOrDefault()?.Steps) { testFile.WriteLine(step.HtmlInstructions); } testFile.Close(); }
public ActionResult Create([FromBody] ExampleMessage model) { if (ModelState.IsValid) { try { model.Author = ExampleContext.Current.User; var messageId = _messageService.Add(model); } catch (Exception) { ModelState.AddModelError(string.Empty, "Unexpected error. Try again."); } } return(RedirectToAction("Detail", "Topic", new { id = model.TopicId })); }
public void HandleMessage(ExampleMessage exampleMessage) { var directionRequest = new DirectionsRequest() { Origin = "607 clear spring ln. leander tx 78641", Destination = exampleMessage.BodyText //TODO: JSON Deserialization? Common message format? Unsure here }; var directions = GoogleMapsApi.GoogleMaps.Directions.Query(directionRequest); var testFile = File.CreateText(Directory.GetCurrentDirectory() + "\\Kbb.txt"); foreach (var step in directions?.Routes?.FirstOrDefault()?.Legs?.FirstOrDefault()?.Steps) { testFile.WriteLine(step.HtmlInstructions); } testFile.Close(); }
public void run() { while (!stopFlag) { try { Thread.Sleep(2000); IMessage <ExampleMessage> message = queue.createMessage(); ExampleMessage messageBody = new ExampleMessage(); messageBody.Field1 = ("Field1Content"); messageBody.Field2 = (0xffffL); Console.WriteLine("Queue: Trying to send message #" + message.Id); message.Body = (messageBody); message.Mandatory = true; queue.sendMessage(message); } catch (Exception e) { Console.WriteLine(e.ToString()); } } }
public static void Enqueue(ExampleMessage message) { var factory = new ConnectionFactory { HostName = "localhost" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: "VehicleQueue", durable: false, exclusive: false, autoDelete: false, arguments: null); var body = Encoding.UTF8.GetBytes(message.BodyText); channel.BasicPublish(exchange: "", routingKey: "VehicleQueue", basicProperties: null, body: body); } }
public int?Add(ExampleMessage model) { try { var entity = new Message { Text = model.Text, TopicId = model.TopicId, AuthorId = model.Author.Id }; var newEntity = _messageRepository.Insert(entity); _provider.SaveChanges(); return(newEntity.Id); } catch (Exception exception) { ExampleContext.Log.Error("MessageService.Add", exception); return(null); } }
public static void Run() { IPublish <ExampleMessage> queue = Configuration.GetQueue <ExampleMessage>(); int i = 0; while (true) { Reset.WaitOne(); i++; var message = new ExampleMessage(i, "I am number " + i); queue.Send(message); Interlocked.Increment(ref _writeCount); if (i == int.MaxValue) { i = 0; } } }
public static void Run() { //IPublish<ExampleMessage> queue = Configuration.GetQueue<ExampleMessage>(); var queue = MonQueFactory.Instance.GetMessagesPublisher <ExampleMessage>(); int i = 0; while (true) { Reset.WaitOne(); i++; var message = new ExampleMessage(i, "I am number " + i); queue.Send(message, QueueMode.WorkQueue); Interlocked.Increment(ref _writeCount); if (i == int.MaxValue) { i = 0; } } }
private static async Task Test() { var qConfig = new QueueConfig(); _configuration.GetSection("RabbitExpress").Bind(qConfig); using (var qc = new QueueClient <MsgPackSerializer>(qConfig)) { IExampleService client = qc.RpcClient <IExampleService>(); Console.WriteLine(client.Calculate(2, 4)); var input = new ExampleMessage { Text = "RabbitExpress Test" }; client.Process(input); ExampleMessage msg = await client.EncodeMessage(input); Console.WriteLine(msg.Text); ExampleMessage decmsg = await client.DecodeMessage(msg); Console.WriteLine(decmsg.Text); Console.ReadLine(); } }
public static void Enqueue(ExampleMessage message) { var factory = new ConnectionFactory { HostName = "localhost" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: "VehicleQueue", durable: false, exclusive: false, autoDelete: false, arguments: null); var body = Encoding.UTF8.GetBytes(message.BodyText); channel.BasicPublish(exchange: "", routingKey: "VehicleQueue", basicProperties: null, body: body); } }
/// <summary> /// When we get the example message, happily report it! /// </summary> public void Handle(ExampleMessage message) { print("Hello from extra listener!\n" + message.CrazyReason); }
public void Handler(ExampleMessage m) { Counts++; Debug.Log("Handling ExampleMessage"); }
public void AddMessage(bool isIn, string senderName, string content) { ExampleMessage newMsg = Instantiate(isIn? msgIn.gameObject : msgOut.gameObject, contentMsg).GetComponent <ExampleMessage>(); newMsg.UpdateContent(senderName, content); }
public static void Main(string[] args) { // Instantiate a server with the port 1337 Server = new Server(1337); // Adding two handlers Server.Dispatcher.AttachHandler(typeof(AuthenticationMessage), new AuthenticationHandler(Server)); Server.Dispatcher.AttachHandler(typeof(ExampleMessage), new ExampleServerHandler(Server)); // Adding middlewares Server.AttachFilter(new ExampleFilter()); // Adding some events Server.Stopped += ServerStopped; Server.ClientConnected += NewClient; Server.ClientDisconnected += LostClient; Server.ClientAuthenticated += ClientAuthenticated; Server.ClientEvicted += ClientEvicted; Server.Starting += ServerStarting; Server.Ready += ServerStarted; // Run the server Server.Run(); // To write some commands while (true) { var line = Console.ReadLine(); switch (line) { case "stop": Console.WriteLine("Stopping server..."); Server.Stop(); SpinWait.SpinUntil(() => Server.Running, 2000); return; case "list": foreach (Client conn in Server.GetClients()) { string auth = conn.Authenticated ? conn.Identifier : "Anonymous"; Console.WriteLine($"- {conn.Id} ({conn.Address}) [{auth}]"); } break; case var val when new Regex(@"kick ([a-zA-Z0-9*]+)").IsMatch(val): var user = (new Regex(@"kick ([a-zA-Z0-9*]+)").Match(line)).Groups[1].Value; if (user == "*") { Server.ForceDisconnectAll(); } else { Server.ForceDisconnectClient(int.Parse(user)); } break; default: var m = new ExampleMessage() { Content = line }; Server.Broadcast(m); Console.WriteLine($"Message '{line}' sent!"); break; } } }
public void Handler(ExampleMessage m) { Counts++; Debug.Log("Handling ExampleMessage"); }
public void OnExampleMessage(ExampleMessageArgs e) { ExampleMessage?.Invoke(this, e); }
IEnumerator Start() { Logger.text = string.Empty; Debug.Log("Starting Messaging Test"); yield return new WaitForSeconds(1); Counts = 0; var m = new ExampleMessage(); var m2 = new CachedExampleMessage(); Messenger.Subscribe(this); Messenger.Publish(m); Assert(() => Counts == 2, "Sub Then Pub"); yield return new WaitForSeconds(1); Messenger.Unsubscribe(this); Messenger.Publish(m2); Messenger.Subscribe(this); Messenger.ClearCache(); Assert(() => Counts == 3, "Cached Sub / Pub"); yield return new WaitForSeconds(1); Messenger.Unsubscribe(this); Messenger<object>.Subscribe(ObjectHandler); Messenger.Publish(m); Messenger.Publish(m2); Assert(() => Counts == 5, "Manual Sub / Pub"); yield return new WaitForSeconds(1); Debug.Log("All Done"); }
public static Task MessageHandlerAsync(ExampleMessage message, CancellationToken token) { Console.WriteLine(message.Id); return(Task.CompletedTask); }
public void OrderWasCreated(ExampleMessage message) { Console.WriteLine("Orders service was called."); Console.WriteLine(message.Text); }