public Customer GetCustomer(CustomerIdentifier customerId) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Got message: {0}", customerId.Id); var typeNameSerialzier = new TypeNameSerializer(); Console.WriteLine("Response Type: {0}", typeNameSerialzier.Serialize(typeof(Customer))); Console.WriteLine("Request Type: {0}", typeNameSerialzier.Serialize(typeof(CustomerIdentifier))); Console.ResetColor(); var messageDescription = MessageDescriptionFormat.Json; var translationFileUri = "./Translations/Json/JavascriptTranslations/GetCustomerTranslation.js"; var translationReturnType = typeof(Customer); var configurationJsonUri = "./ServiceConfigurations/GetCustomerConfiguration.json"; // Wrap the message var wrappedMessage = MessageDescription.Create( customerId, messageDescription, translationFileUri, translationReturnType); // Get Params var @params = translationService.GetMessageParts(wrappedMessage); // Known the appropriate Adaptor var adapter = new RestAdapter(); adapter.Initialize(configurationJsonUri, @params); var result = adapter.Send<Customer>(); return result; }
public SyncronousMessageResponse Send(SyncronousMessageRequest request) { if (this.bus == null || this.busConnectionDetails == null || serviceDetails == null) { throw new ArgumentException("The sender has not been Initialized. Please call the Initialize method first."); } var operation = ServiceOperationCache.Get(request.ServiceId, request.OperationId); var typeNameSerialzier = new TypeNameSerializer(); Console.WriteLine("Response Type: {0}", typeNameSerialzier.Serialize(operation.ResponseType)); Console.WriteLine("Request Type: {0}", typeNameSerialzier.Serialize(operation.RequestType)); var message = JsonConvert.DeserializeObject(request.Message, operation.RequestType); var generic = this.bus.GetType().GetMethod("Request").MakeGenericMethod(operation.RequestType, operation.ResponseType); var result = generic.Invoke(this.bus, new[] { message }); //var result = this.bus.Request<string, string>("hello"); return new SyncronousMessageResponse() { Message = result, OperationId = request.OperationId, ServiceId = request.ServiceId }; }
public Conventions() { // Establish default conventions. ExchangeNamingConvention = TypeNameSerializer.Serialize; TopicNamingConvention = messageType => ""; QueueNamingConvention = (messageType, subscriptionId) => { var typeName = TypeNameSerializer.Serialize(messageType); return(string.Format("{0}_{1}", typeName, subscriptionId)); }; }
public Conventions() { // Establish default conventions. ExchangeNamingConvention = TypeNameSerializer.Serialize; TopicNamingConvention = messageType => ""; QueueNamingConvention = (messageType, subscriptionId) => { var typeName = TypeNameSerializer.Serialize(messageType); return(string.Format("{0}_{1}", typeName, subscriptionId)); }; RpcRoutingKeyNamingConvention = TypeNameSerializer.Serialize; ErrorQueueNamingConvention = () => "EasyNetQ_Default_Error_Queue"; ErrorExchangeNamingConvention = (originalRoutingKey) => "ErrorExchange_" + originalRoutingKey; RpcExchangeNamingConvention = () => "easy_net_q_rpc"; }
public virtual void HandleConsumerError(BasicDeliverEventArgs deliverArgs, Exception exception) { try { Connect(); using (var model = connection.CreateModel()) { var errorExchange = DeclareErrorExchangeQueueStructure(model, deliverArgs.RoutingKey); var messageBody = CreateErrorMessage(deliverArgs, exception); var properties = model.CreateBasicProperties(); properties.SetPersistent(true); properties.Type = TypeNameSerializer.Serialize(typeof(Error)); model.BasicPublish(errorExchange, deliverArgs.RoutingKey, properties, messageBody); } } catch (BrokerUnreachableException) { // thrown if the broker is unreachable during initial creation. logger.ErrorWrite("EasyNetQ Consumer Error Handler cannot connect to Broker\n" + CreateConnectionCheckMessage()); } catch (OperationInterruptedException interruptedException) { // thrown if the broker connection is broken during declare or publish. logger.ErrorWrite("EasyNetQ Consumer Error Handler: Broker connection was closed while attempting to publish Error message.\n" + string.Format("Message was: '{0}'\n", interruptedException.Message) + CreateConnectionCheckMessage()); } catch (Exception unexpecctedException) { // Something else unexpected has gone wrong :( logger.ErrorWrite("EasyNetQ Consumer Error Handler: Failed to publish error message\nException is:\n" + unexpecctedException); } }