資源簡介
使用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.xm
?????文件?????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.xm
?????文件??????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.xm
?????文件??????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個文件信息
- 上一篇:ACTIVEMQ C#下的
- 下一篇:基于Mysql數據庫的C#實現登錄注冊功能
評論
共有 條評論