本文整理汇总了C#中System.Messaging.MessageQueueTransaction类的典型用法代码示例。如果您正苦于以下问题:C# MessageQueueTransaction类的具体用法?C# MessageQueueTransaction怎么用?C# MessageQueueTransaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageQueueTransaction类属于System.Messaging命名空间,在下文中一共展示了MessageQueueTransaction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: btnAdd_Click
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
string queueName = ConfigurationManager.AppSettings["MSMQLocation"];
MessageQueue rmTxnQ = new MessageQueue(queueName);
rmTxnQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(ProcessMessage) });
foreach (ListBoxItem itm in files.Items)
{
MessageQueueTransaction msgTx = new MessageQueueTransaction();
msgTx.Begin();
try
{
string argument = "-i \"{0}\" -o \"{1}\" --preset \"" + ConfigurationManager.AppSettings["HandbrakePreset"] + "\"";
string destination = txtDestination.Text + "\\" + System.IO.Path.GetFileNameWithoutExtension(itm.ToolTip.ToString()) + ".m4v";
ProcessMessage p = new ProcessMessage() { CommandLine = argument, DestinationURL = destination, OrignalFileURL = itm.ToolTip.ToString() };
rmTxnQ.Send(p, msgTx);
results.Items.Insert(0, string.Format("{0} added to queue", p.OrignalFileURL));
msgTx.Commit();
}
catch (Exception ex)
{
results.Items.Insert(0, ex.Message);
msgTx.Abort();
}
}
}
开发者ID:tiernano,项目名称:HandbrakeCluster,代码行数:32,代码来源:MainWindow.xaml.cs
示例2: _orderQueue_PeekCompleted
static void _orderQueue_PeekCompleted(object sender, PeekCompletedEventArgs e)
{
var orderQueue = (MessageQueue)sender;
var transaction = new MessageQueueTransaction();
transaction.Begin();
Order order;
try
{
var receivedMessage = orderQueue.Receive(transaction);
receivedMessage.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
order = Order.DeserializeXml(receivedMessage.Body.ToString());
using (var db = new OrderContext())
{
db.Orders.Add(order);
db.SaveChanges();
}
transaction.Commit();
}
catch
{
// TODO: Log something
transaction.Abort();
}
finally
{
orderQueue.BeginPeek();
}
}
开发者ID:sconno05,项目名称:order-service,代码行数:34,代码来源:Program.cs
示例3: Main
private static void Main(string[] args)
{
const string message = "Testing MSMQ";
List<MessageQueue> queues = CreateQueues(".\\private$\\FirstQueue",
".\\private$\\SecondQueue",
".\\private$\\ThirdQueue");
var sender = new Sender();
var receiver = new Receiver();
/*
* Send to all the queues within a transaction
*/
using (var transaction = new MessageQueueTransaction())
{
transaction.Begin();
foreach (MessageQueue queue in queues)
{
sender.Send(queue, message, transaction);
}
transaction.Commit();
}
/*
* Read from all the queues
*/
receiver.StartReading(queues);
Console.ReadKey();
}
开发者ID:MarcusParkkinen,项目名称:MSMQTransactionsExample,代码行数:33,代码来源:Program.cs
示例4: Run
void Run()
{
MessageQueueTransaction transaction = new MessageQueueTransaction();
while (!shouldStop)
{
try
{
transaction.Begin();
Message message = requestQueue.Receive(new TimeSpan(0, 0, 1), transaction);
responseQueue.Send(message, transaction);
transaction.Commit();
synchronizedInvoke.BeginInvoke(addMessage, new object[] { requestQueueName, message });
}
catch (MessageQueueException e)
{
if (e.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
Console.WriteLine("Receive failure on " + requestQueueName + " " + e.StackTrace,
System.Diagnostics.EventLogEntryType.Error);
}
finally
{
if (transaction.Status == MessageQueueTransactionStatus.Pending)
{
transaction.Abort();
}
}
}
}
开发者ID:untoldwind,项目名称:soatools,代码行数:30,代码来源:MessageListener.cs
示例5: MoveMessage
static void MoveMessage(Message message, string destinationQueueName, bool leaveCopyInSourceQueue)
{
var sourceQueuePath = message.QueuePath;
var destinationQueuePath = MsmqUtil.GetFullPath(destinationQueueName);
using (var transaction = new MessageQueueTransaction())
{
transaction.Begin();
try
{
var sourceQueue = new MessageQueue(sourceQueuePath) {MessageReadPropertyFilter = DefaultFilter()};
var destinationQueue = new MessageQueue(destinationQueuePath);
var msmqMessage = sourceQueue.ReceiveById(message.Id, transaction);
destinationQueue.Send(msmqMessage, transaction);
if (leaveCopyInSourceQueue)
{
sourceQueue.Send(msmqMessage, transaction);
}
transaction.Commit();
}
catch
{
transaction.Abort();
throw;
}
}
Messenger.Default.Send(new MessageMoved(message, sourceQueuePath, destinationQueuePath, leaveCopyInSourceQueue));
}
开发者ID:skinny,项目名称:Rebus,代码行数:32,代码来源:MsmqInteraction.cs
示例6: MangledMessageIsNotReceived
public void MangledMessageIsNotReceived()
{
using (var messageQueue = new MessageQueue(MsmqUtil.GetPath(_inputQueueName)))
{
var transaction = new MessageQueueTransaction();
transaction.Begin();
messageQueue.Send(new Message
{
Extension = Encoding.UTF32.GetBytes("this is definitely not valid UTF8-encoded JSON")
}, transaction);
transaction.Commit();
}
Thread.Sleep(5000);
CleanUpDisposables();
using (var messageQueue = new MessageQueue(MsmqUtil.GetPath(_inputQueueName)))
{
messageQueue.MessageReadPropertyFilter = new MessagePropertyFilter
{
Extension = true
};
var transaction = new MessageQueueTransaction();
transaction.Begin();
var message = messageQueue.Receive(transaction);
Assert.That(message, Is.Not.Null);
Assert.That(Encoding.UTF32.GetString(message.Extension), Is.EqualTo("this is definitely not valid UTF8-encoded JSON"));
transaction.Commit();
}
}
开发者ID:RichieYang,项目名称:Rebus,代码行数:35,代码来源:TestMsmqMangledMessage.cs
示例7: Send
public void Send(Object message)
{
// Open the queue.
using (var queue = new MessageQueue(_queueName.GetQueueFormatName()))
{
// Set the formatter to JSON.
queue.Formatter = new MsmqMessageFormatter();
// Since we're using a transactional queue, make a transaction.
using (MessageQueueTransaction mqt = new MessageQueueTransaction())
{
mqt.Begin();
// Create a simple text message.
Message myMessage = new Message(message, new MsmqMessageFormatter());
myMessage.Label = message.GetType().FullName;
myMessage.ResponseQueue = new MessageQueue(_queueName.GetQueueFormatName());
// Send the message.
queue.Send(myMessage, mqt);
mqt.Commit();
}
}
}
开发者ID:paralect,项目名称:Paralect.ServiceBus,代码行数:25,代码来源:MsmqQueue.cs
示例8: Start
/// <summary>
/// 启动消息侦程序线程
/// </summary>
private void Start(MessageListener listener)
{
ThreadPool.STPStartInfo stp = new ThreadPool.STPStartInfo();
stp.MaxStackSize = MaxThreads;
stp.MaxWorkerThreads = MaxThreads;
ThreadPool.SmartThreadPool smartThreadpool = new ThreadPool.SmartThreadPool(stp);
while (true)
{
MQMessage message = null;
if (messageQueue.QueueConfig.isTransactional)
{
MessageQueueTransaction tran = new MessageQueueTransaction();
message = new MQMessage(tran);
message.Begin();
message.messageContent = messageQueue.Receive(tran).Body.ToString();
}
else
{
message = new MQMessage(null);
message.messageContent = messageQueue.Receive().Body.ToString();
}
System.Threading.Interlocked.Increment(ref Counter);
while (Counter >= MaxThreads)
{
System.Threading.Thread.Sleep(100);
}
smartThreadpool.QueueWorkItem(CallBack, message);
}
}
开发者ID:priceLiu,项目名称:Enterprise.Company,代码行数:33,代码来源:MessageConsumer.cs
示例9: Run
static void Run()
{
MessageQueue queue = null;
MessageQueueTransaction trans = null;
try
{
queue = new MessageQueue();
queue.Path = Constants.QUEUE_PATH;
queue.DefaultPropertiesToSend.Recoverable = true;
trans = new MessageQueueTransaction();
trans.Begin();
MyOrder order = new MyOrder();
order.ID = DateTime.Now.Ticks.ToString();
order.Name = "Order_" + order.ID;
Message msg = new Message(order);
queue.Send(msg, trans);
trans.Commit();
}
catch (Exception ex)
{
trans.Abort();
}
finally
{
queue.Close();
}
Console.WriteLine("message sent..");
}
开发者ID:yoshiao,项目名称:WCF_Samples,代码行数:33,代码来源:Program.cs
示例10: OnPeekCompleted
private void OnPeekCompleted(object sender, PeekCompletedEventArgs e)
{
if (OnMessageReceived == null) return;
var transaction = new MessageQueueTransaction();
transaction.Begin();
try
{
var queueMessage = inputQueue.Receive(transaction);
var headers = GetMessageHeaders(queueMessage);
var message = new ChannelMessage(queueMessage.BodyStream);
message.AddHeader(headers);
OnMessageReceived(this, new MessageReceivedEventArgs { Message = message });
transaction.Commit();
}
catch (Exception)
{
transaction.Abort();
throw;
}
finally
{
inputQueue.BeginPeek();
}
}
开发者ID:Zapote,项目名称:EzBus,代码行数:26,代码来源:MsmqReceivingChannel.cs
示例11: Send2WithLabelWithTransaction
public void Send2WithLabelWithTransaction ()
{
String label1 = "label1";
String label2 = "label2";
Message sent1 = new Message ("Message 1", new BinaryMessageFormatter ());
Message sent2 = new Message ("Message 2", new BinaryMessageFormatter ());
MessageQueue mq = MQUtil.GetQueue (MQUtil.CreateQueueName (), true);
mq.MessageReadPropertyFilter.SetAll ();
Assert.IsTrue(mq.Transactional, "Message Queue should be transactional");
using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
tx.Begin ();
mq.Send (sent1, label1, tx);
mq.Send (sent2, label2, tx);
tx.Commit ();
Message received1 = mq.Receive ();
Assert.IsNotNull (received1.TransactionId, "TransactionId not set");
Message received2 = mq.Receive ();
Assert.IsNotNull (received2.TransactionId, "TransactionId not set");
Assert.AreEqual (received1.TransactionId, received2.TransactionId, "Messages have differing TransactionIds");
Assert.IsTrue (received1.TransactionId.Length > 1);
Assert.AreEqual (sent1.Body, received1.Body, "Message 1 not delivered correctly");
Assert.AreEqual (sent2.Body, received2.Body, "Message 2 not delivered correctly");
Assert.AreEqual (label1, received1.Label, "Label 1 not passed correctly");
Assert.AreEqual (label2, received2.Label, "Label 2 not passed correctly");
}
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:30,代码来源:TransactionMessagingTest.cs
示例12: GetMessageFromQueue
public override void GetMessageFromQueue(string messageId, MessageQueue queue, Action<Message> processMethod)
{
using (var transaction = new MessageQueueTransaction())
{
transaction.Begin();
Logger.DebugFormat("Transaction for {0} started.", messageId);
Message message;
try
{
message = queue.ReceiveById(messageId, TimeSpan.FromSeconds(30), transaction);
Logger.DebugFormat("Message with id {0} received.", messageId);
}
catch (Exception ex)
{
transaction.Abort();
Logger.Error(
string.Concat("Failed to receive message with id ", messageId, "transactions aborted.")
, ex);
return;
}
if (message != null)
{
processMethod(message);
}
if (transaction.Status != MessageQueueTransactionStatus.Aborted)
transaction.Commit();
}
}
开发者ID:mickednk,项目名称:MightyLittle.MQ,代码行数:31,代码来源:TransactionalReceive.cs
示例13: sendDeclMessage
public Boolean sendDeclMessage(string messageId, string outId, int sendType, string messageDetail, int place)
{
if (messageId == null && messageId == ""
&& outId == null && outId == ""
&& messageDetail == null && messageDetail == ""
&& sendType == 0
&& place == 0)
{
return false;
}
MessageQueueTransaction msgTransaction = new MessageQueueTransaction();
try
{
mq = mqFactory.CreateMsgQueueFactory(sendType, place);
using (TransactionScope scope = new TransactionScope())
{
msgTransaction.Begin();
XmlDocument xmldoc = new XmlDocument();
if (place == (int)SendPlace.GOVERNMENT)
{
String key = configUtil.getGovPwd();
messageDetail = AESUtil.AesEncoding(messageDetail, key, Encoding.UTF8);
mq.SendEncryptMessage(messageDetail, msgTransaction, messageId);
}
else
{
xmldoc.LoadXml(messageDetail);
mq.SendMessage(xmldoc, msgTransaction, messageId);
}
Logger.Debug(messageDetail);
messageDeclService.createDeclMessage(messageId, outId, sendType, messageDetail,place);
messageRespService.createResponseMessage(messageId, outId, sendType,place);
scope.Complete();
msgTransaction.Commit();
return true;
}
} catch (Exception e)
{
msgTransaction.Abort();
if ((int)CustomsDeclarationProxy.Constant.CustomsMessageType.MANIFEST== sendType)
{
Logger.Error("shipmentPackId:" + outId + "send and insert manifest message failed!", e);
}
else if ((int)CustomsDeclarationProxy.Constant.CustomsMessageType.ORDER == sendType)
{
Logger.Error("shipmentPackId:" + outId + "send and insert order message failed!", e);
}
return false;
}
}
开发者ID:huangkungit,项目名称:msmq-example,代码行数:59,代码来源:DeclareProxyAPI.cs
示例14: SendInTransactionWithPathNotSet
public void SendInTransactionWithPathNotSet ()
{
MessageQueue q = new MessageQueue ();
Message m = new Message ("foobar", new BinaryMessageFormatter ());
MessageQueueTransaction tx = new MessageQueueTransaction ();
q.Send (m, tx);
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:8,代码来源:FailuresTest.cs
示例15: MovePoisonMessageToErrorQueue
protected void MovePoisonMessageToErrorQueue(Message message, MessageQueueTransaction transaction)
{
var error = $"Message '{message.Id}' is classfied as a poison message and will be moved to '{errorQueue.QueueName}'";
Logger.Error(error);
errorQueue.Send(message, transaction);
}
开发者ID:Particular,项目名称:NServiceBus,代码行数:8,代码来源:ReceiveStrategy.cs
示例16: btnR_Click
private void btnR_Click(object sender, EventArgs e)
{
try
{
if (this.chbChoose1.Checked)
{
MessageQueue queue = new MessageQueue(this.txtMSMQ1.Text) {
Formatter = new BinaryMessageFormatter()
};
System.Messaging.Message message = new System.Messaging.Message();
MessageQueueTransaction transaction = new MessageQueueTransaction();
transaction.Begin();
try
{
message = queue.Receive(TimeSpan.FromMilliseconds(500.0), transaction);
}
catch
{
transaction.Commit();
}
StreamReader reader = new StreamReader(message.BodyStream, Encoding.ASCII);
if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
{
this.txtPath1.Text = this.saveFileDialog1.FileName;
FileStream output = new FileStream(this.txtPath1.Text, FileMode.OpenOrCreate, FileAccess.ReadWrite);
BinaryWriter writer = new BinaryWriter(output);
writer.Write(Encoding.Default.GetBytes(reader.ReadToEnd()));
writer.Flush();
writer.Close();
transaction.Commit();
MessageBox.Show("发送成功!");
}
}
else
{
MessageQueue queue2 = new MessageQueue(this.txtMSMQ1.Text) {
Formatter = new BinaryMessageFormatter()
};
System.Messaging.Message message2 = new System.Messaging.Message();
StreamReader reader2 = new StreamReader(queue2.Receive(TimeSpan.FromMilliseconds(500.0)).BodyStream, Encoding.ASCII);
if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
{
this.txtPath1.Text = this.saveFileDialog1.FileName;
FileStream stream2 = new FileStream(this.txtPath1.Text, FileMode.OpenOrCreate, FileAccess.ReadWrite);
BinaryWriter writer2 = new BinaryWriter(stream2);
writer2.Write(Encoding.Default.GetBytes(reader2.ReadToEnd()));
writer2.Flush();
writer2.Close();
MessageBox.Show("发送成功!");
}
}
}
catch (Exception exception)
{
MessageBox.Show("发送失败!原因:" + exception.Message);
}
}
开发者ID:jimlong45,项目名称:msmqTool,代码行数:57,代码来源:Form1.cs
示例17: MsmqFetchedJob
public MsmqFetchedJob(MessageQueueTransaction transaction, string jobId)
{
if (transaction == null) throw new ArgumentNullException("transaction");
if (jobId == null) throw new ArgumentNullException("jobId");
_transaction = transaction;
JobId = jobId;
}
开发者ID:yonglehou,项目名称:Hangfire.Firebird,代码行数:9,代码来源:MsmqFetchedJob.cs
示例18: Session
public Session(Connection connection, AcknowledgementMode acknowledgementMode)
{
this.connection = connection;
this.acknowledgementMode = acknowledgementMode;
MessageConverter = connection.MessageConverter;
if (this.acknowledgementMode == AcknowledgementMode.Transactional)
{
MessageQueueTransaction = new MessageQueueTransaction();
}
}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:10,代码来源:Session.cs
示例19: Enqueue
public void Enqueue(IDbConnection connection, string queue, string jobId)
{
using (var messageQueue = GetMessageQueue(queue))
using (var message = new Message { Label = jobId })
using (var transaction = new MessageQueueTransaction())
{
transaction.Begin();
messageQueue.Send(message, transaction);
transaction.Commit();
}
}
开发者ID:harriyott,项目名称:Hangfire,代码行数:11,代码来源:MsmqJobQueue.cs
示例20: EnqueueJobId
public static void EnqueueJobId(string queue, string jobId)
{
using (var messageQueue = CleanMsmqQueueAttribute.GetMessageQueue(queue))
using (var message = new Message { Body = jobId, Label = jobId, Formatter = new BinaryMessageFormatter() })
using (var transaction = new MessageQueueTransaction())
{
transaction.Begin();
messageQueue.Send(message, transaction);
transaction.Commit();
}
}
开发者ID:GitHuang,项目名称:Hangfire,代码行数:11,代码来源:MsmqUtils.cs
注:本文中的System.Messaging.MessageQueueTransaction类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论