コード例 #1
0
        public void ProcessTransfer(AMQPData data, long?handle, bool?settled, long?_deliveryId)
        {
            QOS qos = QOS.AT_LEAST_ONCE;

            if (settled.HasValue && settled.Value)
            {
                qos = QOS.AT_MOST_ONCE;
            }
            else
            {
                AMQPDisposition disposition = new AMQPDisposition();
                disposition.Channel = _channel;
                disposition.Role    = RoleCodes.RECEIVER;
                disposition.First   = _deliveryId.Value;
                disposition.Last    = _deliveryId.Value;
                disposition.Settled = true;
                disposition.State   = new AMQPAccepted();
                _client.Send(disposition);
            }

            String topicName = null;

            if (!handle.HasValue || !_usedMappings.ContainsKey(handle.Value))
            {
                return;
            }

            topicName = _usedMappings[handle.Value];
            _dbInterface.StoreMessage(topicName, data.Data, qos);

            if (_listener != null)
            {
                _listener.MessageReceived(MessageType.PUBLISH);
            }
        }
コード例 #2
0
        public static AMQPSection getSection(IByteBuffer buf)
        {
            TLVAmqp value = TLVFactory.getTlv(buf);

            AMQPSection section = null;

            Byte         byteCode = value.Constructor.getDescriptorCode().Value;
            SectionCodes code     = (SectionCodes)byteCode;

            switch (code)
            {
            case SectionCodes.APPLICATION_PROPERTIES:
                section = new ApplicationProperties();
                break;

            case SectionCodes.DATA:
                section = new AMQPData();
                break;

            case SectionCodes.DELIVERY_ANNOTATIONS:
                section = new DeliveryAnnotations();
                break;

            case SectionCodes.FOOTER:
                section = new AMQPFooter();
                break;

            case SectionCodes.HEADER:
                section = new MessageHeader();
                break;

            case SectionCodes.MESSAGE_ANNOTATIONS:
                section = new MessageAnnotations();
                break;

            case SectionCodes.PROPERTIES:
                section = new AMQPProperties();
                break;

            case SectionCodes.SEQUENCE:
                section = new AMQPSequence();
                break;

            case SectionCodes.VALUE:
                section = new AMQPValue();
                break;

            default:
                throw new MalformedMessageException("Received header with unrecognized message section code");
            }

            section.fill(value);

            return(section);
        }
コード例 #3
0
        public void Publish(Topic topic, byte[] content, Boolean retain, Boolean dup)
        {
            AMQPTransfer transfer = new AMQPTransfer();

            transfer.Channel = _channel;
            if (topic.Qos == QOS.AT_MOST_ONCE)
            {
                transfer.Settled = true;
            }
            else
            {
                transfer.Settled = false;
            }

            transfer.More          = false;
            transfer.MessageFormat = new AMQPMessageFormat(0);

            MessageHeader messageHeader = new MessageHeader();

            messageHeader.Durable      = true;
            messageHeader.Priority     = 3;
            messageHeader.Milliseconds = 1000;

            AMQPData data = new AMQPData();

            data.Data = content;

            AMQPSection[] sections = new AMQPSection[1];
            sections[0] = data;
            transfer.addSections(sections);

            if (_usedOutgoingMappings.ContainsKey(topic.Name))
            {
                Int64 handle = _usedOutgoingMappings[topic.Name];
                transfer.Handle = handle;
                _timers.Store(transfer);
                if (transfer.Settled.Value)
                {
                    _timers.Remove((Int32)transfer.DeliveryId.Value);
                }

                _client.Send(transfer);
            }
            else
            {
                Int64 currentHandler = _nextHandle++;
                _usedOutgoingMappings[topic.Name] = currentHandler;
                _usedMappings[currentHandler]     = topic.Name;

                transfer.Handle = currentHandler;
                pendingMessages.Add(transfer);

                AMQPAttach attach = new AMQPAttach();
                attach.Channel              = _channel;
                attach.Name                 = topic.Name;
                attach.Handle               = currentHandler;
                attach.Role                 = RoleCodes.SENDER;
                attach.RcvSettleMode        = ReceiveCodes.FIRST;
                attach.InitialDeliveryCount = 0L;
                AMQPSource source = new AMQPSource();
                source.Address = topic.Name;
                source.Durable = TerminusDurability.NONE;
                source.Timeout = 0;
                source.Dynamic = false;
                attach.Source  = source;
                _client.Send(attach);
            }
        }