示例#1
0
        public MessageSender(String broker, String topicName)
        {
            //Create connection
                try
                {
                    sonicSender = new SonicCommunicator(topicName, broker);
                    cf = sonicSender.GetConnectionFactory();
                    conn = cf.createConnection();
                    session = (Session)conn.createSession(false, Sonic.Jms.SessionMode.AUTO_ACKNOWLEDGE);
                }
                catch (JMSException jmse)
                {
                    throw new Exception("Unable to establish connection to MQ." + jmse.Message + " / " + jmse.InnerException);
                }

                Console.WriteLine("Create Session: " + session.ToString());

                //create the topic
                try
                {
                    topic = session.createTopic(topicName);
                    publisher = session.createProducer(topic);
                    tempTopic = session.createTemporaryTopic();
                    subscriber = session.createConsumer(tempTopic);
                    conn.start();
                }
                catch (JMSException jmse)
                {
                    throw new Exception("Unable to create topic." + jmse.Message + " / " + jmse.InnerException);
                }
        }
        public void SetUp()
        {
            sessionFactoryMock = new Mock<ISessionFactory>(MockBehavior.Loose);
            activeMqMessageMapperMock = new Mock<IActiveMqMessageMapper>();
            destinationEvaluatorMock = new Mock<IDestinationEvaluator>();

            testee = new MessageProducer(
                sessionFactoryMock.Object, 
                activeMqMessageMapperMock.Object,
                destinationEvaluatorMock.Object);
        }
示例#3
0
        public virtual void EnsureOpenConnection()
        {
            if (_connection == null)
                {
                    _connection = GetConnectionFactory().createConnection();
                    _session = (Sonic.Jms.Ext.Session)_connection.createSession(true, Sonic.Jms.SessionMode.AUTO_ACKNOWLEDGE);
                    _topic = _session.createTopic(_topicName);
                    _replier = _session.createProducer(null);

                    _connection.setExceptionListener(this);
                    _connection.start();
                }
        }
        private void EnsureOpenConnection()
        {
            if (_connection != null)
                return;
            _connection = GetNewConnectionFactory().createConnection();
            _session = (Sonic.Jms.Ext.Session)_connection.createSession(true, SessionMode.AUTO_ACKNOWLEDGE);
            _topic = _session.createTopic(_topicName);
            _messageProducer = _session.createProducer(null);
            _messageConsumer = _session.createConsumer(_topic);

            _connection.setExceptionListener(this);
            _connection.start();
        }
 public IMessageProducer CreateProducer()
 {
     Open(Consts.Consumer_DefaultConnectTimeout);
     var producer = new MessageProducer(this);
     return producer;
 }
        /// <summary>
        /// 发布数据至缓存队列
        /// </summary>
        /// <param name="identifier"></param>
        /// <param name="pubMessage"></param>
        internal void PublishToBuffer(MessageProducer producer, PubMessage message )
        {

           // producer.FlowControl(producer,new FlowControlEventArgs());
          

           // Buffer.PublishMessage(producer, pubMessage);
        }
示例#7
0
 public MessageHub(MessageProducer producer)
 {
     _producer = producer;
 }
 public Bridge(MessageProducer <IncomingMessage> prod)
 {
     this.prod = prod;
 }
示例#9
0
    public csSelector(String[] args)
    {
        ParseArgs(args);

        try {
            tibemsUtilities.initSSLParams(serverUrl, args);
        }
        catch (Exception e)
        {
            System.Console.WriteLine("Exception: " + e.Message);
            System.Console.WriteLine(e.StackTrace);
            System.Environment.Exit(-1);
        }

        Console.WriteLine("\n------------------------------------------------------------------------");
        Console.WriteLine("csSelector SAMPLE");
        Console.WriteLine("------------------------------------------------------------------------");
        Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost"));
        Console.WriteLine("User......................... " + ((userName != null)?userName:"******"));
        Console.WriteLine("Queue........................ " + queueName);
        Console.WriteLine("------------------------------------------------------------------------\n");


        if (!noselector)
        {
            Console.WriteLine("\n*** Also try to run this sample with the -noselector");
            Console.WriteLine("*** option to see the difference it makes.");
        }

        try {
            ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl);

            Connection connection = factory.CreateConnection(userName, password);

            Session receive_session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
            Session send_session    = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);

            Queue queue = send_session.CreateQueue(queueName);

            // Start the connection so we can drain the queue and then proceed.
            connection.Start();

            // drain the queue
            MessageConsumer receiver = receive_session.CreateConsumer(queue);

            int drain_count = 0;
            Console.WriteLine("\nDraining the queue " + queueName);

            // read queue until empty
            while (receiver.Receive(1000) != null)
            {
                drain_count++;
            }
            Console.WriteLine("Drained " + drain_count + " messages from the queue");

            // close receiver to prevent any queue messages to be delivered
            receiver.Close();

            // create receivers with selectors
            Console.WriteLine("");
            if (!noselector)
            {
                Console.WriteLine("Creating receivers with selectors:\n");
            }
            else
            {
                Console.WriteLine("Creating receivers without selectors:\n");
            }
            Thread.Sleep(500);

            int receiver_count = 3;
            for (int i = 0; i < receiver_count; i++)
            {
                String selector = null;

                if (!noselector)
                {
                    selector = "count >= " + (i * 4) + " AND count < " + (i * 4 + 4);
                }

                receiver = receive_session.CreateConsumer(queue, selector);

                if (!noselector)
                {
                    Console.WriteLine("Created receiver " + i + " with selector: \"" + selector + "\"");
                }
                else
                {
                    Console.WriteLine("Created receiver " + i);
                }

                receiver.MessageListener = new MyMessageListener(i);
                Thread.Sleep(500);
            }

            // create sender
            MessageProducer sender = send_session.CreateProducer(queue);

            Message message = null;

            int message_number = 0;

            // send 12 messages into queue
            Console.WriteLine("");
            Console.WriteLine("Sending 12 messages into the queue:\n");

            Thread.Sleep(200);

            for (int i = 0; i < 12; i++)
            {
                message = send_session.CreateMessage();
                message.SetIntProperty("count", message_number);
                sender.Send(message);
                Thread.Sleep(500);
                message_number++;
            }

            // wait for some time while all messages received
            Thread.Sleep(1000);

            connection.Close();
        } catch (EMSException e) {
            Console.Error.WriteLine("Exception in csSelector: " + e.Message);
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(0);
        } catch (ThreadInterruptedException e) {
            Console.Error.WriteLine("Exception in csSelector: " + e.Message);
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(0);
        }
    }
 private void DispatchMessage()
 {
     MessageProducer.Add(SomeMessage);
 }
示例#11
0
    public void Run()
    {
        int                   msgCount       = 0;
        MsgRateChecker        msgRateChecker = null;
        EMSCompletionListener cl             = null;
        int                   numMsgsToPublish;

        try
        {
            Thread.Sleep(500);
        }
        catch (ThreadInterruptedException) {}

        try
        {
            // create the session
            Connection connection = this.MyConnection;
            Session    session    = connection.CreateSession(useTxn, Session.AUTO_ACKNOWLEDGE);

            // create the destination
            Destination destination = CreateDestination(session);

            // create the producer
            MessageProducer msgProducer = session.CreateProducer(null);

            if (async)
            {
                cl = new EMSCompletionListener();
            }

            // set parameters on producer
            msgProducer.DeliveryMode = delMode;
            // Specific for performance
            msgProducer.DisableMessageID        = true;
            msgProducer.DisableMessageTimestamp = true;

            // create the message
            Message msg = CreateMessage(session);

            if (uniqueDests || useTopic)
            {
                numMsgsToPublish = count;
            }
            else
            {
                numMsgsToPublish = count / threads;
            }

            if (compression)
            {
                msg.SetBooleanProperty("JMS_TIBCO_COMPRESS", true);
            }

            // initialize message rate checking
            if (msgRate > 0)
            {
                msgRateChecker = new MsgRateChecker(msgRate);
            }

            startTiming();

            while ((count == 0 || msgCount < numMsgsToPublish) && !stopNow)
            {
                // publish message
                if (async)
                {
                    msgProducer.Send(destination, msg, cl);
                }
                else
                {
                    msgProducer.Send(destination, msg);
                }

                msgCount++;

                // commit messages
                if (useTxn && (msgCount % txnSize) == (txnSize - 1))
                {
                    session.Commit();
                }

                if (msgRate > 0)
                {
                    msgRateChecker.checkMsgRate(msgCount);
                }
            }

            // commit remaining messages
            if (useTxn)
            {
                session.Commit();
            }

            stopTiming(cl, numMsgsToPublish);

            CountSends(msgCount);
        }
        catch (EMSException e)
        {
            Console.Error.WriteLine("Exception in csMsgProducerPerf: " +
                                    e.Message);
            Console.Error.WriteLine(e.StackTrace);

            if (e.LinkedException != null)
            {
                Console.Error.WriteLine("Linked Exception: " +
                                        e.LinkedException.Message);
                Console.Error.WriteLine(e.LinkedException.StackTrace);
            }

            Environment.Exit(-1);
        }
    }