Skip to content
DataMiner DoJo

More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Search in posts
Search in pages
Search in posts
Search in pages
Log in
Menu
  • Updates & Insights
  • Questions
  • Learning
    • E-learning Courses
    • Empower Replay: Limited Edition
    • Tutorials
    • Open Classroom Training
    • Agility
      • Kanban workshop
      • Agile Fundamentals
    • Certification
      • DataMiner Fundamentals
      • DataMiner Configurator
      • DataMiner Automation
      • Scripts & Connectors Developer: HTTP Basics
      • Scripts & Connectors Developer: SNMP Basics
      • Visual Overview – Level 1
      • Verify a certificate
    • Video Library
    • Books We Like
    • >> Go to DataMiner Docs
  • Expert Center
    • Solutions & Use Cases
      • Solutions
      • Use Case Library
    • Markets & Industries
      • Media production
      • Government & defense
      • Content distribution
      • Service providers
      • Partners
      • OSS/BSS
    • Agile
      • Agile Webspace
      • Everything Agile
        • The Agile Manifesto
        • Best Practices
        • Retro Recipes
      • Methodologies
        • The Scrum Framework
        • Kanban
        • Extreme Programming
      • Roles
        • The Product Owner
        • The Agile Coach
        • The Quality & UX Coach (QX)
    • DataMiner DevOps Professional Program
      • About the DevOps Program
      • DataMiner DevOps Support
  • Downloads
  • More
    • Feature Suggestions
    • Climb the leaderboard!
    • Swag Shop
    • Contact
    • Global Feedback Survey
  • Support
  • PARTNERS
    • All Partners
    • Technology Partners
    • Strategic Partner Program
    • Deal Registration
  • >> Go to dataminer.services

Best way to listen for events on Azure Eventhub

Solved681 views13th January 2023
3
Baptiste Pattyn [SLC] [DevOps Advocate]5.72K 19th December 2022 0 Comments

I am looking to create an integration between Azure Eventhub and my DataMiner. I have a piece of code ready to run:

using Microsoft.Azure.EventHubs;

// Replace these values with your own Event Hub connection details
string connectionString = "Endpoint=sb://<YOUR_EVENT_HUB_NAMESPACE>.servicebus.windows.net/;SharedAccessKeyName=<YOUR_SHARED_ACCESS_KEY_NAME>;SharedAccessKey=<YOUR_SHARED_ACCESS_KEY>";
string eventHubName = "<YOUR_EVENT_HUB_NAME>";

// Create a connection to the Event Hub
EventHubClient client = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);

// Create a receiver to listen for events from the Event Hub
EventHubReceiver receiver = client.CreateReceiver("<YOUR_CONSUMER_GROUP>", "<YOUR_PARTITION_ID>", EventPosition.FromEnqueuedTime(DateTime.Now));

// Listen for events asynchronously
while (true)
{
// Receive the next batch of events
IEnumerable<EventData> events = await receiver.ReceiveAsync(100, TimeSpan.FromSeconds(1));

// Process the events
foreach (EventData eventData in events)
{
// Get the event body as a string
string eventBody = Encoding.UTF8.GetString(eventData.Body.Array);

// Do something with the event
Console.WriteLine(eventBody);
}
}

// Close the receiver and client when you're done
receiver.CloseAsync();
client.CloseAsync();

As you can see there is a while true loop in this code to keep the channel open to receive events. What would be the best way to implement this? Should I create a driver or an automation script? Or are there other options?

Baptiste Pattyn [SLC] [DevOps Advocate] Selected answer as best 13th January 2023

1 Answer

  • Active
  • Voted
  • Newest
  • Oldest
3
Tom Waterbley [SLC] [DevOps Catalyst]8.93K Posted 19th December 2022 0 Comments

Would create a connector for this use case. In a QAction you could spin up a new thread that keeps collecting new events. New events are stored in a (concurrent) queue, using your code in the question. Some managing code will need to be written to check if that thread is still active, and spin up a new thread when needed, in order to make sure it's robust. Also don't forget to stop the thread, when the element is being stopped. This can be done in the Dispose method.

A timer in the connector could then trigger the same QAction every x seconds. When that happens, the QAction processes all messages that are available in the queue, and updates the needed parameters in the element.

Baptiste Pattyn [SLC] [DevOps Advocate] Selected answer as best 13th January 2023
You are viewing 1 out of 1 answers, click here to view all answers.
Please login to be able to comment or post an answer.

My DevOps rank

DevOps Members get more insights on their profile page.

My user earnings

0 Dojo credits

Spend your credits in our swag shop.

0 Reputation points

Boost your reputation, climb the leaderboard.

Promo banner DataMiner DevOps Professiona Program
DataMiner Integration Studio (DIS)
Empower Katas
Privacy Policy • Terms & Conditions • Contact

© 2025 Skyline Communications. All rights reserved.

DOJO Q&A widget

Can't find what you need?

? Explore the Q&A DataMiner Docs

[ Placeholder content for popup link ] WordPress Download Manager - Best Download Management Plugin