Beispiel #1
0
        /// <summary>
        /// Creates server from loaded and added options
        /// </summary>
        public MqServer CreateServer()
        {
            MqServerOptions options = new MqServerOptions();

            SetServerPropertyValues(_object, options);

            options.Instances = _object["Instances"] != null
                                    ? _object["Instances"].ToObject <InstanceOptions[]>()
                                    : new InstanceOptions[0];

            MqServer server = new MqServer(options, _clientAuthenticator, _clientAuthorization);

            if (_channelEventHandler != null)
            {
                server.SetDefaultChannelHandler(_channelEventHandler, _channelAuthenticator);
            }

            if (_messageDeliveryHandler != null)
            {
                server.SetDefaultDeliveryHandler(_messageDeliveryHandler);
            }

            if (_clientHandler != null)
            {
                server.ClientHandler = _clientHandler;
            }

            if (_serverMessageHandler != null)
            {
                server.ServerMessageHandler = _serverMessageHandler;
            }

            JObject channelToken = _object["Channels"] as JObject;

            if (channelToken == null)
            {
                return(server);
            }

            foreach (JProperty ctoken in channelToken.Properties())
            {
                ChannelOptions channelOptions;
                if (ctoken.HasValues)
                {
                    channelOptions = CloneFrom(options);
                    SetChannelPropertyValues(ctoken.Value, channelOptions);
                }
                else
                {
                    channelOptions = options;
                }

                Channel channel = server.CreateChannel(ctoken.Name, _channelAuthenticator, _channelEventHandler, _messageDeliveryHandler, channelOptions);

                JObject queueToken = ctoken.Value["Queues"] as JObject;
                if (queueToken == null)
                {
                    continue;
                }

                foreach (JProperty qtoken in queueToken.Properties())
                {
                    ushort contentType = Convert.ToUInt16(qtoken.Name);

                    ChannelQueueOptions queueOptions;
                    if (qtoken.HasValues)
                    {
                        queueOptions = CloneFromAsQueue(channelOptions);
                        SetQueuePropertyValues(qtoken.Value, queueOptions);
                    }
                    else
                    {
                        queueOptions = channelOptions;
                    }

                    channel.CreateQueue(contentType, queueOptions).Wait();
                }
            }

            return(server);
        }
Beispiel #2
0
 private void SetServerPropertyValues(JObject from, MqServerOptions options)
 {
     SetChannelPropertyValues(from, options);
 }