The following procedure describes the process of building and running the Event Hubs SDK samples (send and send_batch) in an Ubuntu desktop environment. The samples enable your Ubuntu machine to act as a device that can connect to an Azure Event Hub.
A computer running the Ubuntu OS.
To run the sample applications you will need an Event Hub to which they can send messages.
To configure an Event Hub, see Create an Event Hub. Be sure to make a note of the Event Hub name and the SendRule and ReceiveRule connection strings; you will need them to complete building the samples.
-
Open a terminal window in Ubuntu.
-
Install the prerequisite packages by issuing the following commands in a terminal window:
sudo apt-get update
sudo apt-get install -y curl libcurl4-openssl-dev uuid-dev uuid g++ make cmake git
- Download the SDK to the machine by issuing the following command in your terminal window:
git clone --recursive https://github.com/Azure/azure-event-hubs.git
You will be prompted for your GitHub username and password -- if you have two-factor authentication enabled for your account, you'll need to generate and then use a personal access token in place of your password.
- Verify that you now have a copy of our source code under the directory ~/azure-event-hubs.
Before performing these steps, you'll need the following prerequisite information:
- Event Hub name.
- Event Hub connection string.
Now, configure the sample:
-
On your Ubuntu machine, open the file ~/azure-event-hubs/c/eventhub_client/samples/send/send.c in a text editor.
-
Scroll down to locate the connection information.
-
Replace the placeholder value for the connectionString variable with your SendRule Event Hub connection string. Replace the placeholder value for the eventHubPath variable with your Event Hub name.
-
Save your changes.
-
Repeat the previous steps, but for step 1 open the file ~/azure-event-hubs/c/eventhub_client/samples/send_batch/send_batch.c.
Before performing this step, you'll need the following prerequisite information:
- Event Hub Name
- Event Hub connection string
- Event Hub consumer group
- Partition number
-
On your Ubuntu machine, open the file ~/azure-event-hubs/c/eventhub_client/samples/receive/receive.c in a text editor.
-
Replace the placeholder value for the connectionString variable with your Event Hub connection string. Replace the placeholder value for the eventHubPath variable with your Event Hub name. Replace the placeholder value for the consumerGroup variable with your consumer group. Replace the placeholder value for the partitionId variable with the desired partition ID.
-
Save your changes.
You can now build the SDK samples using the following command:
~/azure-event-hubs/c/build_all/linux/build.sh
- Run the send sample by issuing the following command:
~/cmake/eventhub_client/samples/send/send
- Run the send_batch sample by issuing the following command:
~/cmake/eventhub_client/samples/send_batch/linux/receive
- Run the receive sample by issuing the following command:
~/cmake/eventhub_client/samples/receive/receive
- For each sample, verify that the sample output messages show Successful. If not, then you may have incorrectly pasted the Event Hub connection information.
Note: The tools folder in this repository includes the CSharp_ConsumeEventsFromEventHub C# Windows application that can receive messages from an Event Hub. This is useful to help you verify that the samples are sending messages correctly to the Event Hub.