public void Initialize(string queueName, string connectionString) { var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); QueueDescription queue; if (!namespaceManager.QueueExists(queueName)) { queue = namespaceManager.CreateQueue(queueName); queue.EnableBatchedOperations = false; queue.EnableExpress = true; queue.DefaultMessageTimeToLive = TimeSpan.FromDays(3); //queue.EnableLargeMessages = true; queue.MaxDeliveryCount = int.MaxValue; //queue.RequiresSession = false; queue.SupportOrdering = true; } else { queue = namespaceManager.GetQueue(queueName); } queueClient = QueueClient.CreateFromConnectionString(connectionString, queueName, ReceiveMode.PeekLock); queueClient.OnMessage(receivedMessage => { try { MessageReceived(receivedMessage); Trace.WriteLine("Processing Service Bus message: " + receivedMessage.SequenceNumber.ToString()); } catch (Exception exc) { receivedMessage.Abandon(); Trace.TraceError(exc.ToString()); } }, new OnMessageOptions { AutoComplete = false, MaxConcurrentCalls = 10000 }); }
public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // Create the queue if it does not exist already var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); //var retryStrategy = new Incremental(5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2)); //var retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(retryStrategy); try { if (!namespaceManager.QueueExists(QueueName)) namespaceManager.CreateQueue(QueueName); } catch (MessagingEntityAlreadyExistsException) { // eat and/or log this one as it's usually caused by a race condition } // Initialize the connection to Service Bus Queue Client = QueueClient.CreateFromConnectionString(connectionString, QueueName, ReceiveMode.PeekLock); IsStopped = false; return base.OnStart(); }
public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; MefLoader.Initialize(); // Create the queue if it does not exist already string connectionString = CloudConfigurationManager.GetSetting("ServiceBus"); string queueName = ConfigurationsSelector.GetSetting("Customer.Queue"); NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); QueueDescription queueDescription = new QueueDescription(queueName) { MaxSizeInMegabytes = 1024, DefaultMessageTimeToLive = TimeSpan.FromMinutes(10), EnablePartitioning = false, //I want to ensure the messages will processed in the right order EnableDeadLetteringOnMessageExpiration = true, LockDuration = TimeSpan.FromMinutes(5) }; if (!namespaceManager.QueueExists(queueName)) namespaceManager.CreateQueue(queueDescription); // Initialize the connection to Service Bus Queue _client = QueueClient.CreateFromConnectionString(connectionString, queueName); return base.OnStart(); }
public override bool OnStart() { //Starting Kernel Trace.TraceInformation("Starting Kernel"); IKernel kernel = new StandardKernel(); this.RegisterServices(kernel); Infra.IoC.Kernel.StartKernel(kernel); Trace.TraceInformation("Kernel Started"); Trace.TraceInformation("Starting Logging"); log4net.Config.XmlConfigurator.Configure(); Trace.TraceInformation("Log Started"); //Starting Listening Queue string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); if (!namespaceManager.QueueExists(QueueName)) { namespaceManager.CreateQueue(QueueName); } // Initialize the connection to Service Bus Queue Client = QueueClient.CreateFromConnectionString(connectionString, QueueName); Trace.TraceInformation("Starting Process Queue Service"); queueProcessorService = Infra.IoC.Kernel.ResolveService<IQueueProcessorService>(); Trace.TraceInformation("Process Queue Service Started"); return base.OnStart(); }
public override bool OnStart() { if (UseMessageBus) { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // Create the queue if it does not exist already string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); if (!namespaceManager.QueueExists(QueueName)) { namespaceManager.CreateQueue(QueueName); } // Initialize the connection to Service Bus Queue QueueClient = QueueClient.CreateFromConnectionString(connectionString, QueueName); } else { } dataSource = new CalculatorDataSource("simulation"); IsStopped = false; return base.OnStart(); }
public QueueSubscriber(string connectionString, string queueName, ILogger logger) { _logger = logger; _client = QueueClient.CreateFromConnectionString(connectionString, queueName); _queueName = queueName; _stopEvent = new ManualResetEvent(false); }
private void button1_Click(object sender, EventArgs e) { lstMensagens.Items.Add("status: Recebendo mensagens..."); this.Refresh(); queueClient = QueueClient.Create(QueueName); BrokeredMessage message = null; while (true) { try { message = queueClient.Receive(TimeSpan.FromSeconds(2)); if (message != null) { lstResultado.Items.Add(string.Format("Id: {0}, Body: {1}", message.MessageId, message.GetBody<string>())); message.Complete(); } else break; } catch (MessagingException error) { if (!error.IsTransient) { lstMensagens.Items.Add("status: " + error.Message); } else ManipularExcecoes(error); } } queueClient.Close(); }
protected override async Task StartAsync() { InfoLogging(string.Format("{0} - Processing", QueueName)); _queueClient = await _clientFactory.CreateServicebusQueueClientAsync(QueueName).ConfigureAwait(false); var stopWatch = new Stopwatch(); while (!Token.IsCancellationRequested) { var messages = await _queueClient .ReceiveBatchAsync(MessageRetrieveCount, MessageRetrieveTimeout) .ConfigureAwait(false); var brokeredMessages = messages as IList<BrokeredMessage> ?? messages.ToList(); if (!brokeredMessages.Any()) continue; var correlationId = Guid.NewGuid().ToString(); DebugLogging(string.Format("{0} - Received {1} new messages", QueueName, brokeredMessages.Count), correlationId); stopWatch.Restart(); await Do(brokeredMessages).ConfigureAwait(false); stopWatch.Stop(); var timeSpan = stopWatch.Elapsed; DebugLogging(string.Format("{0} - Processed messages", QueueName), correlationId, timeSpan.TotalSeconds); } }
public static void Initialise() { ServicePointManager.DefaultConnectionLimit = 12; string connectionString = CloudConfigurationManager.GetSetting("ServiceBus.QueueConnectionString"); QueueClient = QueueClient.CreateFromConnectionString(connectionString, QueueName); }
public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // Create the queue if it does not exist already string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); if (!namespaceManager.QueueExists(QueueName)) { namespaceManager.CreateQueue(QueueName); } // Initialize the connection to Service Bus Queue _client = QueueClient.CreateFromConnectionString(connectionString, QueueName); var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the blob client. var blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. var container = blobClient.GetContainerReference("mycontainer"); // Create the container if it doesn't already exist. container.CreateIfNotExists(); _blob = container.GetBlockBlobReference("myblob"); return base.OnStart(); }
public void TestHostUnreachableResponseTime() { RedisServer.Kill(); var stopWatch = new Stopwatch(); try { using (var client = new QueueClient()) { var homemadeTask = new TaskMessage { Parameters = "params", Queue = "TestQueue" }; stopWatch.Start(); client.Enqueue(homemadeTask); stopWatch.Stop(); } } catch (Exception exception) { Console.WriteLine("Elapsed time: {0} ms", stopWatch.ElapsedMilliseconds); Console.WriteLine(exception.ToString()); RedisServer.Start(); Assert.Pass(); } }
static WorkInBackgroundController() { var serviceBusConnectionString = CloudConfigurationManager.GetSetting(ServiceBusConnectionStringKey); QueueName = CloudConfigurationManager.GetSetting(ServiceBusQueueNameKey); ServiceBusQueueHandler = new ServiceBusQueueHandler(serviceBusConnectionString); QueueClient = ServiceBusQueueHandler.GetQueueClientAsync(QueueName).Result; }
public CommandQueueSubscriber(string connectionString, string queueName, ICommandDispatcher dispatcher, ILogger logger) { _dispatcher = dispatcher; _logger = logger; _client = QueueClient.CreateFromConnectionString(connectionString, queueName); _stopEvent = new ManualResetEvent(false); }
public override bool OnStart() { Trace.TraceError("OnStart() started"); try { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http; var namespaceManager = NamespaceManager.CreateFromConnectionString(_connectionString); //_requestQueueUnderwrite = CreateQueueIfNecessary(namespaceManager, RequestQueueNameUnderwrite); _requestQueueUnderwrite = CreateQueueIfNecessary(namespaceManager, AppConstants.RequestQueueNameUnderwrite); _responseQueueUnderwrite = CreateQueueIfNecessary(namespaceManager, ResponseQueueNameUnderwrite); _requestQueueOnboarding = CreateQueueIfNecessary(namespaceManager, RequestQueueNameOnboarding); return base.OnStart(); } catch (Exception ex) { Trace.TraceError("OnStart() error: " + ex.Message); throw; } }
public override bool OnStart() { ServicePointManager.DefaultConnectionLimit = 12; var connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); _client = QueueClient.CreateFromConnectionString(connectionString, QueueName); return base.OnStart(); }
static void ReceiveQueueMessages(QueueClient Client) { // Configure the callback options. OnMessageOptions options = new OnMessageOptions(); options.AutoComplete = false; options.AutoRenewTimeout = TimeSpan.FromMinutes(1); // Callback to handle received messages. Client.OnMessage((message) => { try { // Process message from queue. Console.WriteLine("Body: " + message.GetBody<string>()); Console.WriteLine("MessageID: " + message.MessageId); Console.WriteLine("Test Property: " + message.Properties["TestProperty"]); // Remove message from queue. message.Complete(); } catch (Exception) { // Indicates a problem, unlock message in queue. message.Abandon(); } }, options); Console.ReadLine(); }
public ReliableQueueClient(string sbNamespace, TokenProvider tokenProvider, string path, ReceiveMode receiveMode, RetryPolicy<ServiceBusTransientErrorDetectionStrategy> policy) : base(sbNamespace, tokenProvider,path,policy) { //create the queue if it doesn't exist bool needsCreation = false; try { needsCreation = !mRetryPolicy.ExecuteAction<bool>(() => mNamespaceManager.QueueExists(path)); } catch (MessagingEntityNotFoundException) { needsCreation = true; } if (needsCreation) { try { mRetryPolicy.ExecuteAction<QueueDescription>(() => mNamespaceManager.CreateQueue(path)); } catch (MessagingEntityAlreadyExistsException) { //ignore this exception because queue already exists } } mRetryPolicy.ExecuteAction(() => mQueueClient = mMessagingFactory.CreateQueueClient(path, receiveMode)); }
public override bool OnStart() { //send the traces to table Storage var storageConnectionString = CloudConfigurationManager.GetSetting("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"); var tlistener = new CustomTraceListener(storageConnectionString, "Aggregator"); Trace.Listeners.Add(tlistener); //persistance storage settings also ManagerSettings.StorageConnectionString = storageConnectionString; // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // Create the queue if it does not exist already string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); if (!namespaceManager.QueueExists(QueueName)) { namespaceManager.CreateQueue(QueueName); } // Initialize the connection to Service Bus Queue _client = QueueClient.CreateFromConnectionString(connectionString, QueueName); _isStopped = false; _storageConnectionString = CloudConfigurationManager.GetSetting("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"); return base.OnStart(); }
protected WindowsServiceBusQueueClient(WindowsServiceBusQueueEndpoint endpoint, IWindowsServiceBusConfiguration sbConfiguration) : base(sbConfiguration) { if (endpoint == null) throw new ArgumentNullException("endpoint"); endpoint.Validate(); try { if (NsManager.QueueExists(endpoint.QueueName) == false) NsManager.CreateQueue(endpoint.QueueName); QueueClient = QueueClient.CreateFromConnectionString(sbConfiguration.ConnectionString, endpoint.QueueName); } catch (Exception ex) { throw new MessagingException( String.Format( "An error occurred while attempting to access the specified Windows service bus queue [{0}]. See inner exception for more details.", endpoint.QueueName), ex); } }
public static void AddToAzureQueue(this object o, string queueName, string nameSpace, string issuerName, string issuerKey) { if (_queueClient == null || queueName.ToLower() != _queueName || nameSpace.ToLower() != _nameSpace || issuerName.ToLower() != _issuerName || issuerKey.ToLower() != _issuerKey) { _queueName = queueName.ToLower(); _nameSpace = nameSpace.ToLower(); _issuerName = issuerName.ToLower(); _issuerKey = issuerKey.ToLower(); ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http; System.Net.ServicePointManager.DefaultConnectionLimit = int.MaxValue; System.Net.ServicePointManager.Expect100Continue = false; System.Net.ServicePointManager.UseNagleAlgorithm = false; var credentials = GetToken(issuerName, issuerKey); // Get a client to the queue var messagingFactory = MessagingFactory.Create(GetAddress(nameSpace), credentials); _queueClient = messagingFactory.CreateQueueClient(queueName); } BrokeredMessage message = new BrokeredMessage(o); _queueClient.Send(message); }
public StoreEventProcessor() { var storageAccount = CloudStorageAccount.Parse(StorageConnectionString); blobClient = storageAccount.CreateCloudBlobClient(); blobContainer = blobClient.GetContainerReference("d2ctutorial"); blobContainer.CreateIfNotExists(); queueClient = QueueClient.CreateFromConnectionString(ServiceBusConnectionString, "d2ctutorial"); }
public TaskOrchestrationClient(string connectionString, string orchestrationTopicName) { this.orchestrationTopicName = orchestrationTopicName; this.connectionString = connectionString; this.messagingFactory = MessagingFactory.CreateFromConnectionString(this.connectionString); this.oxQueueClient = this.messagingFactory.CreateQueueClient(this.orchestrationTopicName); this.defaultConverter = new JsonDataConverter(); }
public HomeController() { var sqlConnString = CloudConfigurationManager.GetSetting("SqlAzureServer"); _searchService = new QueryAndIndexService(sqlConnString); var busConnString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); _client = QueueClient.CreateFromConnectionString(busConnString, "ProcessingQueue"); }
private void MyInit() { // IniWithoutLuis(); InitWithLuis(); _queueClient = QueueClient.Create(QueueName); }
public async Task<long> AddWordToQueueAsync(QueueClient queueClient, string queueName, string word) { Debug.Assert(null != _namespaceManager); var message = new BrokeredMessage(word); await queueClient.SendAsync(message).ConfigureAwait(false); var queue = await _namespaceManager.GetQueueAsync(queueName).ConfigureAwait(false); return queue.MessageCount; }
/// <summary> /// Sends a message to the ServiceFabric Service. /// </summary> /// <returns></returns> public void SendMessage(BrokeredMessage message) { if (_sendClient == null) { _sendClient = QueueClient.CreateFromConnectionString(_serviceUri, _queueName); } _sendClient.Send(message); }
private static void Setup() { if (ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"] == null) throw new ConfigurationErrorsException("Configuração da Fila de Notificação não encontrada"); string configurationSettings = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"].ToString(); _queueClient = QueueClient.CreateFromConnectionString(configurationSettings, QUEUE_NAME); }
public override bool OnStart() { // Create the queue if it does not exist already string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); // Initialize the connection to Service Bus Queue this.client = QueueClient.CreateFromConnectionString(connectionString, QueueName); return base.OnStart(); }
private static Task Loop(QueueClient q, ref int stop) { while (stop == 0) { q.SendBatch(GeneratedMessages(200)); } return Task.FromResult(0); }
/// <summary> /// Sends a message to the ServiceFabric Service. /// </summary> /// <returns></returns> public Task SendMessageAsync(BrokeredMessage message) { if (_sendClient == null) { _sendClient = QueueClient.CreateFromConnectionString(_serviceUri, _queueName); } return _sendClient.SendAsync(message); }
async Task ExceedMaxDelivery(MessagingFactory receiverFactory, string queueName) { var receiver = await receiverFactory.CreateMessageReceiverAsync(queueName, ReceiveMode.PeekLock); while (true) { var msg = await receiver.ReceiveAsync(TimeSpan.Zero); if (msg != null) { Console.WriteLine("Picked up message; DeliveryCount {0}", msg.DeliveryCount); await msg.AbandonAsync(); } else { break; } } var deadletterReceiver = await receiverFactory.CreateMessageReceiverAsync(QueueClient.FormatDeadLetterPath(queueName), ReceiveMode.PeekLock); while (true) { var msg = await deadletterReceiver.ReceiveAsync(TimeSpan.Zero); if (msg != null) { Console.WriteLine("Deadletter message:"); foreach (var prop in msg.Properties) { Console.WriteLine("{0}={1}", prop.Key, prop.Value); } await msg.CompleteAsync(); } else { break; } } }
public Task SendAsync <T>(QueueClient client, T item) where T : InstanceMessage { return(SendAsync(client, item, null)); }
public QueueClient GetFileTransferQueueClientReceiveAndDelete() { var client = QueueClient.Create("files", ReceiveMode.ReceiveAndDelete); return(client); }
static async Task AsyncMain(string[] args) { string queueName = "quickstartqueues-" + Guid.NewGuid().ToString(); Console.WriteLine($"Creating queue: {queueName}"); // Instantiate a QueueClient which will be // used to create and manipulate the queue QueueClient queueClient = new QueueClient(connectionString, queueName); // Create the queue await queueClient.CreateAsync(); Console.WriteLine("\nAdding messages to the queue..."); // Send several messages to the queue await queueClient.SendMessageAsync("First message"); await queueClient.SendMessageAsync("Second message"); // Save the receipt so we can update this message later SendReceipt receipt = await queueClient.SendMessageAsync("Third message"); Console.WriteLine("\nPeek at the messages in the queue..."); // Peek at messages in the queue PeekedMessage[] peekedMessages = await queueClient.PeekMessagesAsync(maxMessages : 10); foreach (PeekedMessage peekedMessage in peekedMessages) { // Display the message Console.WriteLine($"Message: {peekedMessage.MessageText}"); } Console.WriteLine("\nUpdating the third message in the queue..."); // Update a message using the saved receipt from sending the message await queueClient.UpdateMessageAsync(receipt.MessageId, receipt.PopReceipt, "Third message has been updated"); Console.WriteLine("\nReceiving messages from the queue..."); // Get messages from the queue QueueMessage[] messages = await queueClient.ReceiveMessagesAsync(maxMessages : 10); Console.WriteLine("\nPress Enter key to 'process' messages and delete them from the queue..."); Console.ReadLine(); // Process and delete messages from the queue foreach (QueueMessage message in messages) { // "Process" the message Console.WriteLine($"Message: {message.MessageText}"); // Let the service know we're finished with // the message and it can be safely deleted. await queueClient.DeleteMessageAsync(message.MessageId, message.PopReceipt); } Console.WriteLine("\nPress Enter key to delete the queue..."); Console.ReadLine(); // Clean up Console.WriteLine($"Deleting queue: {queueClient.Name}"); await queueClient.DeleteAsync(); Console.WriteLine("Done"); }
protected virtual void CreateTestStorageEntities() { TestQueue = QueueClient.GetQueueReference(string.Format("test-input-{0}", FixtureId)); TestQueue.CreateIfNotExists(); TestQueue.Clear(); // This queue name should really be suffixed by -fsharp, -csharp, -node etc. MobileTablesQueue = QueueClient.GetQueueReference("mobiletables-input"); MobileTablesQueue.CreateIfNotExists(); // do not clear this queue since it is currently shared between fixtures TestInputContainer = BlobClient.GetContainerReference(string.Format("test-input-{0}", FixtureId)); TestInputContainer.CreateIfNotExists(); // Processing a large number of blobs on startup can take a while, // so let's start with an empty container. TestHelpers.ClearContainer(TestInputContainer); TestOutputContainer = BlobClient.GetContainerReference(string.Format("test-output-{0}", FixtureId)); TestOutputContainer.CreateIfNotExists(); TestHelpers.ClearContainer(TestOutputContainer); TestTable = TableClient.GetTableReference("test"); TestTable.CreateIfNotExists(); DeleteEntities(TestTable, "AAA"); DeleteEntities(TestTable, "BBB"); var batch = new TableBatchOperation(); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "001", Region = "West", Name = "Test Entity 1", Status = 0 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "002", Region = "East", Name = "Test Entity 2", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "003", Region = "West", Name = "Test Entity 3", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "004", Region = "West", Name = "Test Entity 4", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "005", Region = "East", Name = "Test Entity 5", Status = 0 }); TestTable.ExecuteBatch(batch); batch = new TableBatchOperation(); batch.Insert(new TestEntity { PartitionKey = "BBB", RowKey = "001", Region = "South", Name = "Test Entity 1", Status = 0 }); batch.Insert(new TestEntity { PartitionKey = "BBB", RowKey = "002", Region = "West", Name = "Test Entity 2", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "BBB", RowKey = "003", Region = "West", Name = "Test Entity 3", Status = 0 }); TestTable.ExecuteBatch(batch); string serviceBusQueueName = string.Format("test-input-{0}", FixtureId); string connectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.ServiceBus); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); namespaceManager.DeleteQueue(serviceBusQueueName); namespaceManager.CreateQueue(serviceBusQueueName); ServiceBusQueueClient = Microsoft.ServiceBus.Messaging.QueueClient.CreateFromConnectionString(connectionString, serviceBusQueueName); }
public static void FakeOut() { var collection = new NameValueCollection(); collection.Add("AzureStorageConnectionString", "AzureStorageConnectionString"); System.Configuration.Fakes.ShimConfigurationManager.AppSettingsGet = () => collection; ShimCloudStorageAccount.ParseString = (s) => { if (s == "AzureStorageConnectionString") { return new ShimCloudStorageAccount { CreateCloudTableClient = () => new ShimCloudTableClient { GetTableReferenceString = (tableReference) => { var zz = new ShimCloudTable() { NameGet = () => "faked", CreateIfNotExistsTableRequestOptionsOperationContext = (x, y) => true, ExecuteQueryTableQueryTableRequestOptionsOperationContext = (query, z, k) => { var entity1 = new ShimDynamicTableEntity().Bind(new RoleTaskDefinitionEntity { PartitionKey = "P1", RowKey = "R1", Name = "Name", Type = "Type", QueueName = "QueueName" }); var entity2 = new ShimDynamicTableEntity().Bind(new RoleTaskDefinitionEntity { PartitionKey = "P2", RowKey = "R2", Name = "Name", Type = "Type", QueueName = "QueueName" }); var result = new List <Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity>(); result.Add(entity1); result.Add(entity2); return result; }, ExecuteTableOperationTableRequestOptionsOperationContext = (operation, z, k) => { return new ShimTableResult(); } }; zz.ExecuteQueryOf1TableQueryOfM0TableRequestOptionsOperationContext <RoleTaskDefinitionEntity>((query, options, context) => { var entity1 = new RoleTaskDefinitionEntity { PartitionKey = "P1", RowKey = "R1", Name = "Name", Type = "Type", QueueName = "QueueName" }; var entity2 = new RoleTaskDefinitionEntity { PartitionKey = "P2", RowKey = "R2", Name = "Name", Type = "Type", QueueName = "QueueName" }; var result = new List <RoleTaskDefinitionEntity>(); result.Add(entity1); result.Add(entity2); return result; }); return zz; } } } } ; throw new Exception("AzureStorageConnectionString was not set correctly!"); }; ShimNamespaceManager.CreateFromConnectionStringString = (connectionString) => { return(new ShimNamespaceManager() { QueueExistsString = (queue) => true, EventHubExistsString = (hub) => true, GetQueueString = (queue) => new ShimQueueDescription { MessageCountDetailsGet = () => new ShimMessageCountDetails { ActiveMessageCountGet = () => 10 } } }); }; var queueClient = QueueClient.CreateFromConnectionString("Endpoint=sb://fake.net/;", "GameEvents"); ShimQueueClient.CreateFromConnectionStringStringString = (connectionstring, table) => { return(new ShimQueueClient(queueClient)); }; } }
/// <summary> /// Create a new instance of the <see cref="ServiceBusSink"/> /// </summary> /// <param name="client">The client</param> public ServiceBusSink(QueueClient client) : this(new QueueClientWrapper(client)) { }
public async Task SendMessage(string queueName, string json) { var _queueClient = new QueueClient(_serviceBusConnectionString, queueName); var message = new Message(Encoding.UTF8.GetBytes(json)); await _queueClient.SendAsync(message); }
public QueueClient GetFileTransferQueueClientPeekLock() { var client = QueueClient.Create("files", ReceiveMode.PeekLock); return(client); }
public SharedBlobQueueProcessor(BlobQueueTriggerExecutor triggerExecutor, QueueClient queue, QueueClient poisonQueue, ILoggerFactory loggerFactory, QueuesOptions queuesOptions) : base(new QueueProcessorOptions(queue, loggerFactory, queuesOptions, poisonQueue)) { _executor = triggerExecutor; }
static async Task Main(string[] args) { Console.WriteLine("Tag Reader Console"); QueueClient queueClient = new QueueClient(AccountDetails.ConnectionString, AccountDetails.QueueName); // Create a sample order RfidTag[] orderItems = new RfidTag[] { new RfidTag() { Product = "Ball", Price = 4.99 }, new RfidTag() { Product = "Whistle", Price = 1.95 }, new RfidTag() { Product = "Bat", Price = 12.99 }, new RfidTag() { Product = "Bat", Price = 12.99 }, new RfidTag() { Product = "Gloves", Price = 7.99 }, new RfidTag() { Product = "Gloves", Price = 7.99 }, new RfidTag() { Product = "Cap", Price = 9.99 }, new RfidTag() { Product = "Cap", Price = 9.99 }, new RfidTag() { Product = "Shirt", Price = 14.99 }, new RfidTag() { Product = "Shirt", Price = 14.99 }, }; // Display the order data. Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Order contains {0} items.", orderItems.Length); Console.ForegroundColor = ConsoleColor.Yellow; double orderTotal = 0.0; foreach (RfidTag tag in orderItems) { Console.WriteLine("{0} - ${1}", tag.Product, tag.Price); orderTotal += tag.Price; } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Order value = ${0}.", orderTotal); Console.WriteLine(); Console.ResetColor(); Console.WriteLine("Press enter to scan..."); Console.ReadLine(); Random random = new Random(DateTime.Now.Millisecond); // Send the order with random duplicate tag reads int sentCount = 0; int position = 0; Console.WriteLine("Reading tags..."); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Cyan; // Comment in to create session id //var sessionId = Guid.NewGuid().ToString(); //Console.WriteLine($"SessionId: { sessionId }"); while (position < 10) { RfidTag rfidTag = orderItems[position]; // Create a new message from the order item RFID tag. var orderJson = JsonConvert.SerializeObject(rfidTag); var tagReadMessage = new Message(Encoding.UTF8.GetBytes(orderJson)); // Comment in to set message id. //tagReadMessage.MessageId = rfidTag.TagId; // Comment in to set session id. //tagReadMessage.SessionId = sessionId; // Send the message await queueClient.SendAsync(tagReadMessage); Console.WriteLine($"Sent: { orderItems[position].Product }"); //Console.WriteLine($"Sent: { orderItems[position].Product } - MessageId: { tagReadMessage.MessageId }"); // Randomly cause a duplicate message to be sent. if (random.NextDouble() > 0.4) { position++; } sentCount++; Thread.Sleep(100); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("{0} total tag reads.", sentCount); Console.WriteLine(); Console.ResetColor(); Console.ReadLine(); }
private static IObjectToTypeConverter <QueueMessage> CreateConverter(QueueClient queue) { return(new CompositeObjectToTypeConverter <QueueMessage>( new OutputConverter <QueueMessage>(new IdentityConverter <QueueMessage>()), new OutputConverter <string>(new StringToStorageQueueMessageConverter(queue)))); }
void ListenOnServiceBusQueue() { /* Create Queue client and listen on message */ _sbQueueClient = QueueClient.CreateFromConnectionString(_sbConnectionString, _sbSMSQueue); OnMessageOptions options = new OnMessageOptions(); options.MaxConcurrentCalls = 1; options.AutoComplete = false; string messageBody = ""; _isRunning = true; _sbQueueClient.OnMessage((message) => { string task; int taskId = 0; try { // Process message from queue. messageBody = message.GetBody <string>(); StringBuilder logMessage = new StringBuilder(); logMessage.AppendLine("SMS Task onMessage: " + messageBody); _incomeMessage++; JObject jsonMessage = JObject.Parse(messageBody); if (jsonMessage["taskId"] == null || jsonMessage["task"] == null) { _appLogger.Warn("Incomplete message:" + messageBody); _ignoreMessage++; } else { taskId = int.Parse(jsonMessage["taskId"].ToString()); task = jsonMessage["task"].ToString().ToLower(); _appLogger.Info("Received task: " + task); if (task == "send sms") { string smsProvider = jsonMessage["smsProvider"].ToString().ToLower(); switch (smsProvider) { case "twilio": TwilioThread twillo = new TwilioThread(_twilioAccountId, _twilioToken, _twilioPhoneNumber, jsonMessage, taskId); Thread twilloThread = new Thread(new ThreadStart(twillo.ThreadProc)); twilloThread.IsBackground = false; twilloThread.Start(); break; } _processedMessage++; } else { _ignoreMessage++; } } message.Complete(); } catch (Exception ex) { // Indicates a problem, unlock message in subscription. _failMessage++; message.Complete(); StringBuilder logMessage = new StringBuilder(); logMessage.AppendLine("SMS Task Exception: " + ex.Message); logMessage.AppendLine("SMS Task Message: " + messageBody); _appLogger.Error(logMessage); AzureSQLHelper.OperationTaskModel operationTask = new AzureSQLHelper.OperationTaskModel(); operationTask.UpdateTaskByFail(taskId, ex.Message); } }, options); }
protected AzureQueueService(QueueClient queueClient, JsonSerializerOptions jsonOptions) { _queueClient = queueClient; _jsonOptions = jsonOptions; }
public async Task SendQueueMessage(string entityPath, string message) { var queueClient = new QueueClient(connectionString, entityPath); await queueClient.SendAsync(new Message(Encoding.UTF8.GetBytes(message))); }
/// <summary> /// Creates a new instance of the ServiceBusNotificationService class /// </summary> public ServiceBusNotificationService(IConfiguration configuration, IOptions <NotificationServiceOptions> options, ILogger <ServiceBusNotificationService> logger) { try { this.configuration = configuration; if (options?.Value == null) { throw new ArgumentNullException(nameof(options), "No configuration is defined for the notification service in the appsettings.json."); } if (options.Value.ServiceBus == null) { throw new ArgumentNullException(nameof(options), "No ServiceBus element is defined in the configuration for the notification service in the appsettings.json."); } if (string.IsNullOrWhiteSpace(options.Value.ServiceBus.ConnectionString)) { throw new ArgumentNullException(nameof(options), "No connection string is defined in the configuration of the Service Bus notification service in the appsettings.json."); } if (string.IsNullOrWhiteSpace(options.Value.ServiceBus.QueueName)) { throw new ArgumentNullException(nameof(options), "No queue name is defined in the configuration of the Service Bus notification service in the appsettings.json."); } this.options = options.Value; this.logger = logger; if (this.options.ServiceBus.ConnectionString.ToLower().StartsWith("endpoint=")) { logger.LogInformation("Using Service Bus connectionString to connect to the Service Bus namespace..."); queueClient = new QueueClient(this.options.ServiceBus.ConnectionString, this.options.ServiceBus.QueueName); } else if (this.options.ServiceBus.ConnectionString.ToLower().EndsWith(".servicebus.windows.net")) { logger.LogInformation("Using System-Assigned Managed Instance to connect to the Service Bus namespace..."); var tokenProvider = new ManagedIdentityTokenProvider(); queueClient = new QueueClient(this.options.ServiceBus.ConnectionString, this.options.ServiceBus.QueueName, tokenProvider); } else { logger.LogError("The Service Bus connectionString format is wrong", this.options.ServiceBus.ConnectionString); } logger.LogInformation("QueueClient successfully created.ConnectionString = [{connectionstring}] QueueName = [{queuename}]", this.options.ServiceBus.ConnectionString, this.options.ServiceBus.QueueName); var instrumentationKey = configuration["ApplicationInsights:InstrumentationKey"]; if (string.IsNullOrWhiteSpace(instrumentationKey)) { return; } } catch (Exception ex) { logger.LogError(ex, "An error occurred while creating an instance of the ServiceBusNotificationService class"); throw; } }
/// <summary> /// Shurtcut for running this <see cref="Source{TOut,TMat}"/> with a <see cref="ServiceBusSink"/>. /// The returned <see cref="Task"/> will be completed with Success when reaching the /// normal end of the stream, or completed with Failure if there is a failure signaled in the stream. /// </summary> public static Task ToServiceBus <TMat>(this Source <IEnumerable <BrokeredMessage>, TMat> source, QueueClient client, IMaterializer materializer) { return(source.RunWith(new ServiceBusSink(client), materializer)); }
protected override void OnStart() { workerQueueClient = messagingFactory.CreateQueueClient(workerQueueName); deciderSender = messagingFactory.CreateMessageSender(orchestratorQueueName, workerQueueName); }
public DisposingQueue(QueueClient queue, IDictionary <string, string> metadata) { queue.CreateAsync(metadata: metadata).Wait(); this.QueueClient = queue; }
public QueueStorageService(IOptions <StorageSettings> setting) { _connectionString = setting.Value.ConnectionString; _client = new QueueClient(_connectionString, "samplequeue"); }
/// <summary> /// Creates a new instance of Azure Service Bus Queue by connection string and queue name /// </summary> /// <param name="connectionString">Service Bus connection string</param> /// <param name="queueName">Queue name in Service Bus. If queue doesn't exist it will be created for you.</param> /// <param name="createIfNotExists">If true, will try to create the queue if it doesn't exist. You must have permissions to do so though.</param> public AzureServiceBusQueuePublisher(string connectionString, string queueName, bool createIfNotExists) { _client = new QueueClient(connectionString, queueName); _queueName = queueName; }
public virtual QueueClient GetInputQueue(string queueName) { return(QueueClient.CreateFromConnectionString(ConnectionString, queueName)); }
public GuyInTuxedo(QueueClient queueClient) { _queueClient = queueClient; _hitPoints = MaxHitPoints; }
private QueueClient BuildQueueClient(string queueName) { return(QueueClient.CreateFromConnectionString(_appOptions.Value.ServiceBusConnectionString, queueName)); }
protected async Task <bool> ProcessQueueMessage(CancellationToken cancellationToken) { var queueClient = new QueueClient(_config.OperationConnection, _config.QueueName); QueueMessage queueMessage = null; Message msg = null; using (var op = _telemetryClient.StartOperation <DependencyTelemetry>("GetMessage")) { op.Telemetry.Properties.Add("Run", _config.Run); op.Telemetry.Properties.Add("WhatIf", _config.WhatIf.ToString()); op.Telemetry.Properties.Add("OperationConnection", queueClient.AccountName); op.Telemetry.Properties.Add("QueueName", _config.QueueName); op.Telemetry.Properties.Add("VisibilityTimeout", _config.VisibilityTimeout.ToString()); await queueClient.CreateIfNotExistsAsync(cancellationToken : cancellationToken); if (queueClient.Exists()) { queueMessage = await queueClient.ReceiveMessageAsync(TimeSpan.FromMinutes(_config.VisibilityTimeout), cancellationToken); if (queueMessage != null) { msg = Message.FromString(queueMessage.MessageText); } } op.Telemetry.Properties.Add("QueueEmpty", (queueMessage == null).ToString()); } if (msg == null) { return(false); } if (msg.Action.Equals("ProcessAccount", StringComparison.InvariantCultureIgnoreCase)) { _logger.LogInformation("ProcessAccount"); //Create one queue message for each container in the source account using (var op = _telemetryClient.StartOperation <DependencyTelemetry>("ProcessAccount")) { var sourceBlobServiceClient = new BlobServiceClient(_config.SourceConnection); int containerCount = 0; foreach (var container in sourceBlobServiceClient.GetBlobContainers()) { await queueClient.SendMessageAsync((new Message() { Action = "ProcessPath", Container = container.Name, Path = string.Empty }).ToString()); containerCount++; } op.Telemetry.Properties.Add("Run", _config.Run); op.Telemetry.Properties.Add("WhatIf", _config.WhatIf.ToString()); op.Telemetry.Properties.Add("SourceConnection", sourceBlobServiceClient.AccountName); op.Telemetry.Properties.Add("containerCount", containerCount.ToString()); } } else if (msg.Action.Equals("ProcessPath", StringComparison.InvariantCultureIgnoreCase)) { _logger.LogInformation($"ProcessPath: {msg.Container} {msg.Path}"); using (var op = _telemetryClient.StartOperation <DependencyTelemetry>("ProcessPath")) { var sourceBlobServiceClient = new BlobServiceClient(_config.SourceConnection); var sourceBlobContainerClient = sourceBlobServiceClient.GetBlobContainerClient(msg.Container); var sasBuilder = new BlobSasBuilder() { BlobContainerName = msg.Container, Resource = "c", ExpiresOn = DateTimeOffset.UtcNow.AddMinutes(_config.VisibilityTimeout) }; sasBuilder.SetPermissions(BlobAccountSasPermissions.Read); Uri sasUri = sourceBlobContainerClient.GenerateSasUri(sasBuilder); var sourceBlobs = new ConcurrentDictionary <string, BlobInfo>(); var destinationBlobServiceClient = new BlobServiceClient(_config.DestinationConnection); var destinationBlobContainerClient = destinationBlobServiceClient.GetBlobContainerClient(msg.Container); var destinationBlobs = new ConcurrentDictionary <string, BlobInfo>(); await destinationBlobContainerClient.CreateIfNotExistsAsync(); var operationBlobServiceClient = new BlobServiceClient(_config.OperationConnection); var operationBlobContainerClient = operationBlobServiceClient.GetBlobContainerClient(msg.Container); await operationBlobContainerClient.CreateIfNotExistsAsync(); long blobCount = 0; long blobBytes = 0; long blobCountMoved = 0; long blobBytesMoved = 0; long subPrefixes = 0; string fileName = "status.csv"; var blobs = new Dictionary <string, SourceDestinationInfo>(); if (string.IsNullOrEmpty(_config.Delimiter)) { _config.Delimiter = "/"; } if (_config.ThreadCount < 1) { _config.ThreadCount = Environment.ProcessorCount * 8; } var slim = new SemaphoreSlim(_config.ThreadCount); var getSourceTask = Task.Run(async() => { await foreach (var item in sourceBlobContainerClient.GetBlobsByHierarchyAsync(prefix: msg.Path, delimiter: _config.Delimiter, cancellationToken: cancellationToken)) { if (item.IsPrefix) { await queueClient.SendMessageAsync((new Message() { Action = "ProcessPath", Container = msg.Container, Path = item.Prefix }).ToString()); subPrefixes++; } else if (item.IsBlob) { sourceBlobs.TryAdd(item.Blob.Name, new BlobInfo(item.Blob.Properties)); } } }); var getDestinationTask = Task.Run(async() => { await foreach (var item in destinationBlobContainerClient.GetBlobsByHierarchyAsync(prefix: msg.Path, delimiter: _config.Delimiter, cancellationToken: cancellationToken)) { if (item.IsBlob) { destinationBlobs.TryAdd(item.Blob.Name, new BlobInfo(item.Blob.Properties)); } } }); await Task.WhenAll(getSourceTask, getDestinationTask); if (File.Exists(fileName)) { File.Delete(fileName); } using (StreamWriter sw = new StreamWriter(fileName)) { await sw.WriteLineAsync($"File,Source Size,Source MD5,Source Last Modified,Destination Size,Destination MD5,Destination Last Modified"); foreach (var item in sourceBlobs) { if (destinationBlobs.ContainsKey(item.Key)) { var destinationBlob = destinationBlobs[item.Key]; await sw.WriteLineAsync($"{item.Key},{item.Value.Size},{item.Value.ContentMD5},{item.Value.LastModified},{destinationBlob.Size},{destinationBlob.ContentMD5},{destinationBlob.LastModified}"); blobs.Add(item.Key, new SourceDestinationInfo(item.Value, destinationBlob)); } else { await sw.WriteLineAsync($"{item.Key},{item.Value.Size},{item.Value.ContentMD5},{item.Value.LastModified},,,"); blobs.Add(item.Key, new SourceDestinationInfo(item.Value)); } } } var toUpload = operationBlobContainerClient.GetBlobClient($"{msg.Path}{fileName}"); await toUpload.DeleteIfExistsAsync(cancellationToken : cancellationToken); await toUpload.UploadAsync(fileName, cancellationToken : cancellationToken); var blobSet = new ConcurrentBag <Task>(); foreach (var blob in blobs) { blobSet.Add(Task.Run(async() => { await slim.WaitAsync(cancellationToken); if (blob.Value.Destination == null || blob.Value.Source.LastModified > blob.Value.Destination.LastModified) { if (!_config.WhatIf) { var dest = destinationBlobContainerClient.GetBlobClient(blob.Key); var source = sourceBlobContainerClient.GetBlobClient(blob.Key); await dest.SyncCopyFromUriAsync(new Uri($"{source.Uri.AbsoluteUri}{sasUri.Query}")); } Interlocked.Add(ref blobCountMoved, 1); Interlocked.Add(ref blobBytesMoved, blob.Value.Source.Size); } Interlocked.Add(ref blobCount, 1); Interlocked.Add(ref blobBytes, blob.Value.Source.Size); slim.Release(); })); } await Task.WhenAll(blobSet.ToArray()); op.Telemetry.Properties.Add("Run", _config.Run); op.Telemetry.Properties.Add("WhatIf", _config.WhatIf.ToString()); op.Telemetry.Properties.Add("ThreadCount", _config.ThreadCount.ToString()); op.Telemetry.Properties.Add("Container", msg.Container); op.Telemetry.Properties.Add("SourceConnection", sourceBlobServiceClient.AccountName); op.Telemetry.Properties.Add("DestinationConnection", destinationBlobServiceClient.AccountName); op.Telemetry.Properties.Add("Delimiter", _config.Delimiter); op.Telemetry.Properties.Add("Prefix", msg.Path); op.Telemetry.Properties.Add("blobCount", blobCount.ToString()); op.Telemetry.Properties.Add("blobBytes", blobBytes.ToString()); op.Telemetry.Properties.Add("blobCountMoved", blobCountMoved.ToString()); op.Telemetry.Properties.Add("blobBytesMoved", blobBytesMoved.ToString()); op.Telemetry.Properties.Add("subPrefixes", subPrefixes.ToString()); } } using (var op = _telemetryClient.StartOperation <DependencyTelemetry>("Remove Queue Message")) { op.Telemetry.Properties.Add("Run", _config.Run); op.Telemetry.Properties.Add("WhatIf", _config.WhatIf.ToString()); op.Telemetry.Properties.Add("OperationConnection", queueClient.AccountName); op.Telemetry.Properties.Add("QueueName", _config.QueueName); await queueClient.DeleteMessageAsync(queueMessage.MessageId, queueMessage.PopReceipt, cancellationToken : cancellationToken); } return(true); }
public QueueClient GetSettingsQueueClient() { var client = QueueClient.Create("settings", ReceiveMode.PeekLock); return(client); }
/// <summary> /// Creates a <see cref="Sink{TIn,TMat}"/> for the Azure ServiceBus /// </summary> /// <param name="client">The client</param> /// <returns>The <see cref="Sink{TIn,TMat}"/> for the Azure ServiceBus</returns> public static Sink <IEnumerable <BrokeredMessage>, Task> Create(QueueClient client) { return(Sink.FromGraph(new ServiceBusSink(client))); }
public static void StartListener(this QueueClient queueClient, OnReceiveMessageCallback onReceiveMessageCallback, ReceiveMode receiveMode = ReceiveMode.PeekLock, bool requiresSession = false) { queueClient.StartListener(new OnReceiveMessageCallbackDelegator(onReceiveMessageCallback), receiveMode, requiresSession); }
protected override Task CopyMessageToPoisonQueueAsync(QueueMessage message, QueueClient poisonQueue, CancellationToken cancellationToken) { // determine the poison queue based on the storage account // of the triggering blob, or default poisonQueue = GetPoisonQueue(message) ?? poisonQueue; return(base.CopyMessageToPoisonQueueAsync(message, poisonQueue, cancellationToken)); }
public IActionResult PostRequest([FromBody] Request request) { if (!Request.Headers.ContainsKey(_pttoken)) { return(BadRequest("pttoken not specified")); } if (request == null) { return(BadRequest("Body format of the request is wrong")); } TelemetryClient telemetryClient = new TelemetryClient(); try { Guid tokenGuid = Guid.Parse(Request.Headers[_pttoken]); var queryToken = from t in _db.Tokens where t.GuidToken == tokenGuid select t; if (!queryToken.Any()) { return(BadRequest("Incorrect pttoken")); } Token token = queryToken.FirstOrDefault(); var queryMaxUsages = from s in _db.Subscriptions where s.Id == token.SubscriptionId select s.Limit; if (!queryMaxUsages.Any()) { return(StatusCode(500, "Subscription not found")); } int limit = queryMaxUsages.FirstOrDefault(); if (token.Usages >= limit) { return(BadRequest("Your subscription limit was exceeded")); } _db.Tokens.Find(token.Id).Usages++; _db.SaveChanges(); } catch (Exception e) { telemetryClient.TrackException(e); return(StatusCode(500, e.Message)); } request.Timestamp = DateTime.Now; request.Guid = Guid.NewGuid(); QueueClient client = QueueClient.CreateFromConnectionString(_connectionString, _queueName); BrokeredMessage message = new BrokeredMessage(request); client.Send(message); _memoryCach.Set <Response>(request.Guid, null, TimeSpan.FromMinutes(2)); _waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, request.Guid.ToString()); telemetryClient.TrackEvent(String.Format(@"{0} Message {1} sent to queue", request.Guid, request.Name)); //Wait for the response using the same timeout as for the cache _waitHandle.WaitOne(TimeSpan.FromMinutes(2)); Response response; if (_memoryCach.TryGetValue(request.Guid, out response)) { _memoryCach.Remove(request.Guid); } return(Ok(response)); }