void InitializeMsmq(Action onSuccess) { if (_config.InstallMsmq && !Msmq.IsInstalled) { try { Msmq.Install(); onSuccess(); } catch (Exception ex) { _logger.Log(ex.Message); } } else { if (Msmq.IsInstalled) { onSuccess(); } else { _logger.Log("Msmq is not installed. Create the bus with InstallMsmqIfNeeded and run as administrator."); } } }
// With 1000000 / 100 bytes // Sent 14665 per second // Received 10641 per second // // Sent 1000000 messages in 87672 ms / 1000 bytes // 11406 per second // 1000000 messages received in 142412 ms // Received 7021 per second // (had to increase the default msmq storage size to 2G) public void Msmq() { const long numberOfMessages = 1000000; var msmq = new Msmq<byte[]>(); new ShootoutTest(msmq, msmq).Run(1000, numberOfMessages); }
public MessageProcessor() { msmq = new Msmq <MessageBase <LogEvent> >(ConfigurationManager.AppSettings["RantaLogQueue"]); logEventManager = new LogEventManager(); lockObject = new object(); }
public LogService() { try { msmq = new Msmq <MessageBase <LogEvent> >(ConfigurationManager.AppSettings["RantaLogQueue"]); } catch (Exception ex) { LocalLog.Error(ex.ToString()); } }
public void TestMethod1() { var msmq = new Msmq <MessageBase <string> >(ConfigurationManager.AppSettings["RantaLogQueue"]); var message = new MessageBase <string> { Guid = Guid.NewGuid(), Content = "Hello World" }; msmq.Enqueue(message); var message2 = msmq.Dequeue(); Assert.IsNotNull(message2); Assert.AreEqual(message.Guid, message2.Guid); Assert.AreEqual(message.Content, message2.Content); }
public async Task SaveComment(CommentDto comment) { if (!comment.ProductId.HasValue) { throw new ArgumentNullException(nameof(comment.ProductId), "SaveComment service exeption"); } if (string.IsNullOrWhiteSpace(comment.PosterName)) { throw new ArgumentNullException(nameof(comment.PosterName), "SaveComment service exeption"); } if (string.IsNullOrWhiteSpace(comment.Description)) { throw new ArgumentNullException(nameof(comment.Description), "SaveComment service exeption"); } try { await _repository.SaveComment(comment).ConfigureAwait(false); } catch (Exception ex) { Msmq.Save(MsmqConst.NotSavedComments, comment); throw new Exception(ex.Message, ex); } }
protected override void OnSend(Message message, TimeSpan timeout) { int length; MessageProperties properties = message.Properties; Stream stream = null; MsmqIntegrationMessageProperty property = MsmqIntegrationMessageProperty.Get(message); if (property == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("MsmqMessageDoesntHaveIntegrationProperty"))); } if (property.Body != null) { stream = this.factory.Serialize(property); } if (stream == null) { length = 0; } else { if (stream.Length > 0x7fffffffL) { throw TraceUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("MessageSizeMustBeInIntegerRange")), message); } length = (int)stream.Length; } using (MsmqIntegrationOutputMessage message2 = new MsmqIntegrationOutputMessage(this.factory, length, this.RemoteAddress, property)) { message2.ApplyCertificateIfNeeded(this.certificateTokenProvider, this.factory.MsmqTransportSecurity.MsmqAuthenticationMode, timeout); if (stream != null) { int num3; stream.Position = 0L; for (int i = length; i > 0; i -= num3) { num3 = stream.Read(message2.Body.Buffer, 0, i); } } bool lockHeld = false; try { Msmq.EnterXPSendLock(out lockHeld, this.factory.MsmqTransportSecurity.MsmqProtectionLevel); this.msmqQueue.Send(message2, this.transactionMode); MsmqDiagnostics.DatagramSent(message2.MessageId, message); property.Id = MsmqMessageId.ToString(message2.MessageId.Buffer); } catch (MsmqException exception) { if (exception.FaultSender) { base.Fault(); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception.Normalized); } finally { if (lockHeld) { Msmq.LeaveXPSendLock(); } } } }
public void Msmq(int messageSize, long numberOfMessages) { var msmq = new Msmq<byte[]>(); new ShootoutTest(msmq, msmq).Run(messageSize, numberOfMessages); }
protected override void OnSend(Message message, TimeSpan timeout) { MessageProperties properties = message.Properties; Stream stream = null; MsmqIntegrationMessageProperty property = MsmqIntegrationMessageProperty.Get(message); if (null == property) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.GetString(SR.MsmqMessageDoesntHaveIntegrationProperty))); } if (null != property.Body) { stream = this.factory.Serialize(property); } int size; if (stream == null) { size = 0; } else { if (stream.Length > int.MaxValue) { throw TraceUtility.ThrowHelperError(new ProtocolException(SR.GetString(SR.MessageSizeMustBeInIntegerRange)), message); } size = (int)stream.Length; } using (MsmqIntegrationOutputMessage msmqMessage = new MsmqIntegrationOutputMessage(this.factory, size, this.RemoteAddress, property)) { msmqMessage.ApplyCertificateIfNeeded(this.certificateTokenProvider, this.factory.MsmqTransportSecurity.MsmqAuthenticationMode, timeout); if (stream != null) { stream.Position = 0; for (int bytesRemaining = size; bytesRemaining > 0;) { int bytesRead = stream.Read(msmqMessage.Body.Buffer, 0, bytesRemaining); bytesRemaining -= bytesRead; } } bool lockHeld = false; try { Msmq.EnterXPSendLock(out lockHeld, this.factory.MsmqTransportSecurity.MsmqProtectionLevel); this.msmqQueue.Send(msmqMessage, this.transactionMode); MsmqDiagnostics.DatagramSent(msmqMessage.MessageId, message); property.Id = MsmqMessageId.ToString(msmqMessage.MessageId.Buffer); } catch (MsmqException ex) { if (ex.FaultSender) { this.Fault(); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex.Normalized); } finally { if (lockHeld) { Msmq.LeaveXPSendLock(); } } } }