{"id":385,"date":"2019-04-09T03:19:15","date_gmt":"2019-04-09T03:19:15","guid":{"rendered":"http:\/\/jackofalltradesmasterofsome.com\/blog\/?p=385"},"modified":"2019-04-09T03:24:37","modified_gmt":"2019-04-09T03:24:37","slug":"create-a-nodejs-client-application-to-submit-data-to-event-hubs","status":"publish","type":"post","link":"https:\/\/jackofalltradesmasterofsome.com\/blog\/2019\/04\/09\/create-a-nodejs-client-application-to-submit-data-to-event-hubs\/","title":{"rendered":"Create a NodeJS Client Application to Submit Data to Event Hubs"},"content":{"rendered":"\n<p>Now that we have <a href=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/2019\/04\/09\/provisioning-an-azure-event-hub-to-capture-real-time-streaming-data\/\">provisioned a Event Hub in Azure<\/a>, let&#8217;s Create a NodeJS Client Application to Submit Data to Event Hubs.<\/p>\n\n\n\n<p>Prerequisites <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Visual Studio 2017<\/li><li>Install NodeJS SDK<\/li><\/ul>\n\n\n\n<!--more-->\n\n\n\n<ul class=\"wp-block-list\"><li>From Visual Studio, select \u201ctool->Get Tools and Features\u201d and from the window, select \u201cnode.js\u201d development to add the appropriate libraries to your Visual Studio Instance. <\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"323\" height=\"329\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-10.png\" alt=\"\" class=\"wp-image-386\" srcset=\"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-10.png 323w, https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-10-295x300.png 295w\" sizes=\"auto, (max-width: 323px) 100vw, 323px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\"><li>Start a command prompt window in the location of where your script will reside. For this example we will use C:\\EventHub<\/li><li>Create a package for the application using \u201cnpm init\u201d<ol><li>Accept all defaults in the set up and select \u201cyes\u201d<\/li><li>You will be prompted with the package.json that will be created for you<\/li><\/ol><\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"421\" height=\"261\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-11.png\" alt=\"\" class=\"wp-image-387\" srcset=\"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-11.png 421w, https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-11-300x186.png 300w\" sizes=\"auto, (max-width: 421px) 100vw, 421px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"421\" height=\"261\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-12.png\" alt=\"\" class=\"wp-image-388\" srcset=\"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-12.png 421w, https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-12-300x186.png 300w\" sizes=\"auto, (max-width: 421px) 100vw, 421px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>You must install the Azure SDK Package by running the command \u201cnpm install azure-event-hubs\u201d<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"610\" height=\"199\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-13.png\" alt=\"\" class=\"wp-image-389\" srcset=\"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-13.png 610w, https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-13-300x98.png 300w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Navigate back to Azure to the security profile you created and copy the connection key. Place this in the js script file for the connection. This script just intermittently sends data to event hubs using a json string. <\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"192\" height=\"280\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-14.png\" alt=\"\" class=\"wp-image-390\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"437\" height=\"187\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-15.png\" alt=\"\" class=\"wp-image-391\" srcset=\"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-15.png 437w, https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-15-300x128.png 300w\" sizes=\"auto, (max-width: 437px) 100vw, 437px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Run the following application in command \u201cnode eventclient.js\u201d to begin sending messages to the Event Hub.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"310\" height=\"203\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-16.png\" alt=\"\" class=\"wp-image-392\" srcset=\"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-16.png 310w, https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-16-300x196.png 300w\" sizes=\"auto, (max-width: 310px) 100vw, 310px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>If you navigate back to Azure, you will see the events being recorded in the Event Hub.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"505\" height=\"215\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-17.png\" alt=\"\" class=\"wp-image-393\" srcset=\"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-17.png 505w, https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-17-300x128.png 300w\" sizes=\"auto, (max-width: 505px) 100vw, 505px\" \/><\/figure>\n\n\n\n<p><strong>Reading Data in Event Hubs<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Follow the same commands from the previous section to set up node and the json file via command prompt.<ol><li>npm init<\/li><li>npm install azure-event-hubs<\/li><\/ol><\/li><li>Update the script with the connection string that was set up as send and listen shared access policy.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"356\" height=\"292\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-18.png\" alt=\"\" class=\"wp-image-394\" srcset=\"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-18.png 356w, https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-18-300x246.png 300w\" sizes=\"auto, (max-width: 356px) 100vw, 356px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Run the command \u201cnode eventreader.js\u201d to being to read the messages going into Event Hub.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"275\" height=\"218\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2019\/04\/image-19.png\" alt=\"\" class=\"wp-image-395\"\/><\/figure>\n\n\n\n<p><a href=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/2019\/04\/09\/provisioning-an-azure-event-hub-to-capture-real-time-streaming-data\/\">Part 1 &#8211; Provisioning Event Hubs<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that we have provisioned a Event Hub in Azure, let&#8217;s Create a NodeJS Client Application to Submit Data to Event Hubs. Prerequisites Visual Studio 2017 Install NodeJS SDK<\/p>\n","protected":false},"author":1,"featured_media":135,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,28,27,11,86,85],"tags":[15,13,83],"class_list":["post-385","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","category-azure","category-big-data","category-data-warehouse","category-event-hub","category-sql-server","tag-big-data","tag-etl","tag-event-hub"],"_links":{"self":[{"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts\/385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/comments?post=385"}],"version-history":[{"count":5,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts\/385\/revisions"}],"predecessor-version":[{"id":403,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts\/385\/revisions\/403"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/media\/135"}],"wp:attachment":[{"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/media?parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/categories?post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/tags?post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}