Example #1
0
        private static void WriteQueue(RequestQueueSchema queue, StringBuilder builder)
        {
            var notFirst = false;

            if (!string.IsNullOrWhiteSpace(queue.Name))
            {
                builder.Append($"Name = \"{queue.Name}\"");
                notFirst = true;
            }
            if (queue.Durable)
            {
                if (notFirst)
                {
                    builder.Append(", ");
                }
                builder.Append("Durable = true");
                notFirst = true;
            }
            if (!queue.AutoDelete)
            {
                if (notFirst)
                {
                    builder.Append(", ");
                }
                builder.Append("AutoDelete = false");
            }
        }
Example #2
0
 public CallSchemaGreen(CallSchemaGreen @base, string name, string codeName, int requestTypeId, int?responseTypeId = null,
                        ContentType contentType = null, string routingKey = null, RequestQueueSchema requestQueue = null,
                        ExchangeSchema exchange = null, ExchangeSchema responseExchange = null) : base(name, codeName, contentType,
                                                                                                       routingKey, exchange)
 {
     ResponseExchange = responseExchange;
     RequestQueue     = requestQueue;
     RequestTypeId    = requestTypeId;
     ResponseTypeId   = responseTypeId;
 }
Example #3
0
 public CallSchemaGreen(string name, string codeName, int requestTypeId, int?responseTypeId = null,
                        ContentType contentType = null, string routingKey = null, RequestQueueSchema requestQueue = null,
                        ExchangeSchema exchange = null, ExchangeSchema responseExchange = null) : base(name, codeName, contentType,
                                                                                                       routingKey, exchange)
 {
     if (responseExchange != null && responseExchange.Type == ExchangeKind.Fanout)
     {
         throw new SchemaException($"Cannot set fanount response exchange in endpoint {name}");
     }
     ResponseExchange = responseExchange;
     RequestQueue     = requestQueue;
     RequestTypeId    = requestTypeId;
     ResponseTypeId   = responseTypeId;
 }
Example #4
0
        private static CallSchemaGreen JsonToCall(JProperty evProp, IDictionary <string, TypeSchemaGreen> known)
        {
            if (!(evProp.Value is JObject jobj))
            {
                throw new SchemaFormatException($"Invalid call description at path {evProp.Path}");
            }
            TypeSchemaGreen requestType;

            if (jobj.TryGetValue("request", out var tkn))
            {
                try
                {
                    requestType = GetFieldType(tkn.ToObject <string>(), known);
                }
                catch (Exception ex)
                {
                    throw new SchemaFormatException($"Invalid call request type found at path {tkn.Path}", ex);
                }
            }
            else
            {
                throw new SchemaFormatException($"No call request type found at path {evProp.Path}");
            }

            TypeSchemaGreen responseType = null;

            if (jobj.TryGetValue("response", out tkn))
            {
                try
                {
                    responseType = GetFieldType(tkn.ToObject <string>(), known);
                }
                catch (Exception ex)
                {
                    throw new SchemaFormatException($"Invalid call request type found at path {tkn.Path}", ex);
                }
            }



            var codeName = (string)null;

            if (jobj.TryGetValue("title", StringComparison.InvariantCultureIgnoreCase, out tkn))
            {
                try
                {
                    codeName = tkn.ToObject <string>();
                }
                catch (Exception ex)
                {
                    throw new SchemaFormatException(
                              $"Invalid token in codeName description at path {tkn.Path}", ex);
                }
            }
            ExchangeSchema exchange = null;

            if (jobj.TryGetValue("exchange", out tkn))
            {
                exchange = JsonToExchange(tkn);
            }

            ExchangeSchema responseExchange = null;

            if (jobj.TryGetValue("responseExchange", out tkn))
            {
                responseExchange = JsonToExchange(tkn);
            }

            var routingKey = (string)null;

            if (jobj.TryGetValue("routingKey", StringComparison.InvariantCultureIgnoreCase, out tkn))
            {
                try
                {
                    routingKey = tkn.ToObject <string>();
                }
                catch (Exception ex)
                {
                    throw new SchemaFormatException(
                              $"Invalid token in routing description at path {tkn.Path}", ex);
                }
            }



            RequestQueueSchema queue = null;

            if (jobj.TryGetValue("queue", out tkn))
            {
                queue = JsonToRequestQueue(tkn);
            }


            ContentType contentType = null;

            if (jobj.TryGetValue("contentType", StringComparison.InvariantCultureIgnoreCase, out tkn))
            {
                try
                {
                    contentType = new ContentType(tkn.ToObject <string>());
                }
                catch (Exception ex)
                {
                    throw new SchemaFormatException(
                              $"Invalid token in content type description at path {tkn.Path}", ex);
                }
            }

            return(new CallSchemaGreen(evProp.Name, codeName, requestType.Id,
                                       responseType?.Id, contentType, routingKey, queue, exchange, responseExchange));
        }