• 大小: 708KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: C#
  • 标签: activemq  

资源简介

使用C# 下activemq 接收数据流的例子

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Apache.NMS;
using Apache.NMS.ActiveMQ;
using System.IO;

namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        public int n = 1; 

        public Form1()
        {
            InitializeComponent();
            InitConsumer();
            
            

        }
         public string filename;
        public FileStream fs;
        
        public void InitConsumer()
        {
            this.Hide();
            //创建连接工厂
            IConnectionFactory factory = new ConnectionFactory(“tcp://192.168.27.118:61616“);
            //通过工厂构建连接
            IConnection connection = factory.CreateConnection();
            //这个是连接的客户端名称标识
            connection.ClientId = “firstQueueListener“;
            //启动连接,监听的话要主动启动连接
            connection.Start();
            //通过连接创建一个会话
            ISession session = connection.CreateSession();
            //通过会话创建一个消费者,这里就是Queue这种会话类型的监听参数设置
            IMessageConsumer consumer = session.CreateConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue(“00001“) “filter=‘demo‘“);
            //注册监听事件
            consumer.Listener += new MessageListener(consumer_Listener);
            //connection.Stop();
            //connection.Close();  

        }
        public IStreamMessage ifs;

        void consumer_Listener(IMessage message)
        {
          
             ifs = (IStreamMessage)message;
            //异步调用下,否则无法回归主线程
            this.label1.Invoke(new DelegateRevMessage(RevMessage) ifs);

        }

        public delegate void DelegateRevMessage(IStreamMessage message);

        public void RevMessage(IStreamMessage message)
        {
            this.Hide();
            
            // this.label2.Text += string.Format(@“接收到:{0}{1}“ message.Text Environment.NewLine);
            Byte[] bytPic = new Byte[600000];
            ifs.ReadBytes(bytPic);
            int fslen = bytPic.Length;

            string filename;
            
            //string path1 = System.DateTime.Now.ToShortDateString();
            //string path2 = Convert.ToString(n++);
            //string path3 = “D:\baowen“;
            //string path4 = “.xml“;
            //Directory.CreateDirectory(“D:\baowen“);

            filename = “D:\\1.xml“;
            FileStream fs = new FileStream(filename FileMode.Create);
            
            fs.Write(bytPic 0 fslen);

            fs.Flush();
            fs.Close();//关闭写入filestream
            ifs.ClearBody();

            MessageBox.Show(“报文接收成功d:\\1.xml“);
        }
        #region 私有方法 处理窗体的 显示 隐藏 关闭(退出)
        private void ExitMainForm()
        {
            if (MessageBox.Show(“您确定要退出数据接收程序吗?“ “确认退出“ MessageBoxButtons.OKCancel MessageBoxIcon.Question MessageBo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1027  2016-04-07 14:26  WindowsFormsApplication4\streammsg-jieshou.sln

    ..A..H.     11776  2016-04-07 14:22  WindowsFormsApplication4\streammsg-jieshou.suo

    ..A..H.     43008  2016-04-13 16:04  WindowsFormsApplication4\streammsg-jieshou.v12.suo

     文件     100000  2016-04-12 12:15  WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\1.xml

     文件     753664  2013-05-31 17:55  WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\Apache.NMS.ActiveMQ.dll

     文件    3638784  2013-05-31 17:55  WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\Apache.NMS.ActiveMQ.pdb

     文件     541193  2013-05-31 17:55  WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\Apache.NMS.ActiveMQ.xml

     文件      81920  2013-05-20 17:37  WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\Apache.NMS.dll

     文件     220672  2013-05-20 17:37  WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\Apache.NMS.pdb

     文件     145105  2013-05-20 17:37  WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\Apache.NMS.xml

     文件      30208  2016-04-13 16:09  WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\WindowsFormsApplication4.exe

     文件      26112  2016-04-13 16:09  WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\WindowsFormsApplication4.pdb

     文件      22704  2016-04-13 16:08  WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\WindowsFormsApplication4.vshost.exe

     文件        490  2015-07-10 19:01  WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\WindowsFormsApplication4.vshost.exe.manifest

     文件       5292  2016-04-13 16:08  WindowsFormsApplication4\WindowsFormsApplication4\main.cs

     文件       6756  2016-04-13 09:38  WindowsFormsApplication4\WindowsFormsApplication4\main.Designer.cs

     文件      32164  2016-04-13 09:38  WindowsFormsApplication4\WindowsFormsApplication4\main.resx

     文件       1231  2016-04-10 09:54  WindowsFormsApplication4\WindowsFormsApplication4\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7039  2016-04-12 14:11  WindowsFormsApplication4\WindowsFormsApplication4\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1340  2016-04-13 16:09  WindowsFormsApplication4\WindowsFormsApplication4\obj\Debug\streammsg-jieshou.csproj.FileListAbsolute.txt

     文件        846  2016-04-13 16:09  WindowsFormsApplication4\WindowsFormsApplication4\obj\Debug\streammsg-jieshou.csproj.GenerateResource.Cache

     文件      30208  2016-04-13 16:09  WindowsFormsApplication4\WindowsFormsApplication4\obj\Debug\WindowsFormsApplication4.exe

     文件      17536  2016-04-13 16:09  WindowsFormsApplication4\WindowsFormsApplication4\obj\Debug\WindowsFormsApplication4.Form1.resources

     文件      26112  2016-04-13 16:09  WindowsFormsApplication4\WindowsFormsApplication4\obj\Debug\WindowsFormsApplication4.pdb

     文件        180  2016-04-13 16:09  WindowsFormsApplication4\WindowsFormsApplication4\obj\Debug\WindowsFormsApplication4.Properties.Resources.resources

     文件        505  2016-04-12 11:55  WindowsFormsApplication4\WindowsFormsApplication4\Program.cs

     文件       1372  2016-04-07 14:22  WindowsFormsApplication4\WindowsFormsApplication4\Properties\AssemblyInfo.cs

     文件       2900  2016-04-07 14:22  WindowsFormsApplication4\WindowsFormsApplication4\Properties\Resources.Designer.cs

     文件       5612  2016-04-07 14:22  WindowsFormsApplication4\WindowsFormsApplication4\Properties\Resources.resx

     文件       1111  2016-04-07 14:22  WindowsFormsApplication4\WindowsFormsApplication4\Properties\Settings.Designer.cs

............此处省略14个文件信息

评论

共有 条评论