public async Task Stash(object message, IActorRef sender) { /*var factory = new ConnectionFactory() { HostName = this.BootstrapServers }; * using (var connection = factory.CreateConnection()) * using (var channel = connection.CreateModel()) * { * channel.QueueDeclare(queue: this.Topic, * durable: false, * exclusive: false, * autoDelete: false, * arguments: null); * * var msgJson = JsonConvert.SerializeObject(message, new JsonSerializerSettings * { * TypeNameHandling = TypeNameHandling.All * }); * var bodyObject = new StashObject(Serialization.SerializedActorPath(sender), msgJson); * * var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(bodyObject, new JsonSerializerSettings * { * TypeNameHandling = TypeNameHandling.All * })); * * channel.BasicPublish(exchange: "", * routingKey: this.Topic, * basicProperties: null, * body: body); * * }*/ var msgJson = JsonConvert.SerializeObject(message, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); var bodyObject = new StashObject(Serialization.SerializedActorPath(sender), msgJson); var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(bodyObject, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All })); _model.BasicPublish(this.Topic, "directexchange_key", null, body); }
public void Unstash() { /*var factory = new ConnectionFactory() { HostName = this.BootstrapServers }; * using (var connection = factory.CreateConnection()) * using (var channel = connection.CreateModel()) * { * channel.QueueDeclare(queue: this.Topic, * durable: false, * exclusive: false, * autoDelete: false, * arguments: null); * * var consumer = new EventingBasicConsumer(channel); * * * var a = channel.BasicGet(queue: this.Topic, autoAck: true); * if (a != null) * { * var body = a.Body.ToArray(); * * var stashObject = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(body), new JsonSerializerSettings * { * TypeNameHandling = TypeNameHandling.All * }); * StashObject asd = (StashObject)stashObject; * var provider = ((ActorSystemImpl)_context.System).Provider; * var newActorRef = provider.ResolveActorRef(asd.ActorRef); * var message = JsonConvert.DeserializeObject(asd.Message, new JsonSerializerSettings * { * TypeNameHandling = TypeNameHandling.All * }); * Envelope envelope = new Envelope(message, newActorRef); * Dispatch(envelope); * } * }*/ //_model.BasicQos(1,0,false); var messageBody = _model.BasicGet(queue: this.Topic, autoAck: true); bool isMessageCorrupt = false; if (messageBody != null) { var stashObject = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(messageBody.Body.ToArray()), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, Error = delegate(object sender, ErrorEventArgs args) { args.ErrorContext.Handled = true; isMessageCorrupt = true; } }); if (isMessageCorrupt) { return; } StashObject asd = (StashObject)stashObject; var provider = ((ActorSystemImpl)_context.System).Provider; var newActorRef = provider.ResolveActorRef(asd.ActorRef); var message = JsonConvert.DeserializeObject(asd.Message, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); Envelope envelope = new Envelope(message, newActorRef); Dispatch(envelope); } }