예제 #1
0
        public void mCreateJmsSessionAndSendMsg()
        {
            Utils.ToLog("mCreateJmsSessionAndSendMsg");
            string TmpFileName = CreateTmpSpoolMessageFile(Msgtext);


            //Sonic.Jms.Ext.Connection connect = GetJmsConnection();
            JMSCOMCLIENTLib.CJMSQueueConnection connect = SonicCom.GetJmsConnection();
            if (connect != null)
            {
                //  if (SendMsg(Msgtext, connect))
                if (SonicCom.SendMsg(Msgtext, connect))
                {
                    try
                    {
                        File.Delete(TmpFileName);
                        Utils.ToLog("Отправил сообщение и  Удалил временный файл");
                    }
                    catch (Exception e)
                    {
                        Utils.ToLog("[Error] при удалении временного файла " + e.Message);
                    }
                }
                else
                {
                    Utils.ToLog("Не Отправил сообщение ");
                }
                connect.close();
            }
        }
예제 #2
0
        static internal JMSCOMCLIENTLib.CJMSQueueConnection GetJmsConnection()
        {
            JMSCOMCLIENTLib.CJMSQueueConnectionFactory factory;

            factory = new JMSCOMCLIENTLib.CJMSQueueConnectionFactory();
            factory.initialize2(iniFile.JMSHost, iniFile.JMSPort, "tcp", iniFile.JMSLogin, iniFile.JMSPassword);
            JMSCOMCLIENTLib.CJMSQueueConnection connect = null;
            int TryCount = 0;

            while ((connect == null) && (TryCount < 5))
            {
                try
                {
                    connect = factory.createQueueConnection();
                    Utils.ToCardLog("connect = factory.createQueueConnection();");
                    connect.setPingInterval(30);
                    return(connect);
                }
                //catch (Sonic.Jms.JMSException jmse)
                catch (Exception jmse)
                {
                    Utils.ToLog("[Error] Не могу подсоединится к сессии" + jmse.Message);
                    TryCount++;
                }
            }
            return(null);
        }
예제 #3
0
        static internal bool SendMsg(string text, JMSCOMCLIENTLib.CJMSQueueConnection connect)
        {
            try
            {
                JMSCOMCLIENTLib.CJMSQueueSession session = connect.createQueueSession(0, 2);
                JMSCOMCLIENTLib.CJMSQueue        mQueue  = session.createQueue(iniFile.JMSQueue);
                //Sonic.Jms.Queue mQueue = session.createQueue(iniFile.JMSQueue);
                //Sonic.Jms.MessageProducer sender = session.createProducer(mQueue);
                JMSCOMCLIENTLib.CJMSQueueSender sender = session.createSender(mQueue);
                connect.start();

                JMSCOMCLIENTLib.CJMSTextMessage Tm = session.createTextMessage();
                //Sonic.Jms.TextMessage Tm = session.createTextMessage();

                Tm.setJMSType("XML");
                Tm.setText(text);

                sender.send((JMSCOMCLIENTLib.CJMSMessage)Tm);

                Utils.ToLog("Отправил сообщение в шину " + text, 8);
                sender.close();
                session.close();
                //  connect.close();


                return(true);
            }

            catch (Exception e)
            {
                Utils.ToLog("[Error] CreateJmsSessionAndSendMsg " + e.Message);
                return(false);
            }
        }
예제 #4
0
        public bool TrySendOldJms()
        {
            try
            {
                DirectoryInfo di = new DirectoryInfo(Utils.TmpSpoolFilePath);
                if (!di.Exists)
                {
                    di.Create();
                }
                if (di.GetFiles("*.spl").Length == 0)
                {
                    return(true);
                }

                //  Sonic.Jms.Ext.Connection connect = GetJmsConnection();
                Utils.ToCardLog("JMSCOMCLIENTLib.CJMSQueueConnection connect = SonicCom.GetJmsConnection();");
                JMSCOMCLIENTLib.CJMSQueueConnection connect = SonicCom.GetJmsConnection();
                foreach (FileInfo fi in di.GetFiles("*.spl"))
                {
                    try
                    {
                        if (connect != null)
                        {
                            //if (SendMsg(File.ReadAllText(fi.FullName), connect))
                            if (SonicCom.SendMsg(File.ReadAllText(fi.FullName), connect))
                            {
                                try
                                {
                                    File.Delete(fi.FullName);
                                    Utils.ToLog("Удалил временный файл");
                                }
                                catch (Exception e)
                                {
                                    Utils.ToLog("[Error] при удалении временного файла " + e.Message);
                                }
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception ee)
                    {
                        Utils.ToLog("[Error] TrySendOldJms " + ee.Message);
                        return(true);
                    }
                }
                connect.close();
                return(true);
            }
            catch (Exception e)
            {
                Utils.ToLog("[Error] TrySendOldJms " + e.Message);
                return(true);
            }
        }