<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Reenu Saluja</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/reenusaluja/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/reenusaluja/feed.xml</link>
    <description>Handling High volume events with Azure Event hub</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:24:22 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Deploy your first smart contract on azure ethereum consortium blockchain</title>
      <link>https://docs.microsoft.com/archive/blogs/reenusaluja/deploy-your-first-smart-contract-on-azure-ethereum-consortium-blockchain</link>
      <pubDate>Mon, 12 Mar 2018 10:13:25 GMT</pubDate>
      <dc:creator><![CDATA[ReenuSaluja]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/reenusaluja/?p=85</guid>
      <description><![CDATA[As we know Blockchain like Bitcoin and Ethereum, ledgers for recording virtual currency...]]></description>
      <content:encoded><![CDATA[As we know Blockchain like Bitcoin and Ethereum, ledgers for recording virtual currency transactions, is booming, however, it is much more than just a virtual currency. It’s a transformational technology with the potential to extend digital transformation beyond a company’s walls and into the processes it shares with suppliers, customers and partners. Microsoft Azure provide a strong backbone for this transformational technology implementation. Azure as an open, flexible, and scalable platform, supports a rapidly growing number of distributed ledger technologies that address specific business and technical requirements for security, performance, and operational processes.

Although, Financial use cases and implementation of blockchain technology are in the highlight because of substantial interest of influential parties such as financial institutes, banks, Financial tech start-ups and investors. At the same time non-financial use cases of Blockchain are getting momentum and equally significant importance to a number of industries like supply chain, manufacturing, healthcare and many more.

Today, Let’s take a scenario of non-financial sector i. e. an Automaker which releases a product containing defective parts resulting in costly recalls and repairs. They can use blockchain to trace the supplier of the faulty parts more efficiently. Finally reducing time and labour costs.

<img width="1024" height="576" class="alignnone size-large wp-image-95" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/113-1024x576.jpg" />

<strong>Let’s scope the scenario</strong>

We will create Automaker Scenario on Azure Blockchain. In this blog we will limit our scope for entry raw material and finding details of raw material in our Blockchain Network

Let’s get started.

To get this implemented, at high level we will follow below steps:
<ul>
 	<li>Create azure ethereum consortium blockchain</li>
 	<li>Create smart contracts</li>
 	<li>Deploy smart contracts on azure ethereum consortium blockchain</li>
 	<li>Test our contract on azure ethereum consortium blockchain.</li>
</ul>
<strong>Prerequisite</strong>

You will need:
<ul>
 	<li>A desktop computer (Host) running on Windows 10 or Mac OSX</li>
 	<li>An active Azure subscription</li>
 	<li>An Active internet connection</li>
</ul>
<strong>Step 1: Create azure ethereum consortium blockchain</strong>

Go to <a href="https://portal.azure.com/">https://portal.azure.com</a> click on  <img width="134" height="30" class="alignnone wp-image-125" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/44.png" />and select Ethereum Consortium Blockchain.

<img width="727" height="878" class="alignnone wp-image-135" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/56.png" />

On next few screens put all required information and click on create. Deployment should take 5-10 minutes to complete.

Now we have created Ethereum Consortium Blockchain.

We would need RPC details of our blockchain network in further steps. We will save these values at some place for later use. To get those values

&nbsp;

Click on <img width="177" height="34" class="alignnone wp-image-145" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/63.png" /> from left side. Select your resource group. From “overview” tab find details on “Deployments”.

<img width="1024" height="282" class="alignnone size-large wp-image-155" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/72-1024x282.png" />

It will provide you details of the deployments. Like shown below

<img width="1024" height="304" class="alignnone size-large wp-image-165" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/82-1024x304.png" />

Select first deployment, which looks like “microsoft-azure-blockchain.azure-blockchain-servi-&lt;timestamp&gt;”.

In next window copy value of “ethereum-rpc-endpoint” from output section. We would need this value in next steps to deploy contract on  Ethereum Consortium Blockchain  network.

<img width="1024" height="329" class="alignnone size-large wp-image-175" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/92-1024x329.png" />

It’s time to move to next step to create smart contracts

<strong>Step 2: Create smart contracts</strong>

We will use Solidity to write smart contract. To get more details on Solidity, please go through solidity documentation <a href="https://solidity.readthedocs.io/en/develop/">https://solidity.readthedocs.io/en/develop/</a>. To create a solidity smart contract you can use Visual studio code with Solidity extension or Remix. You can download Solidity extension for Visual studio code from <a href="https://marketplace.visualstudio.com/items?itemName=ConsenSys.Solidity">https://marketplace.visualstudio.com/items?itemName=ConsenSys.Solidity</a>

You can get more details about Remix from github location

<a href="https://github.com/ethereum/remix">https://github.com/ethereum/remix</a>

&nbsp;

Today we will use remix to write smart contract. We will write 1 smart contract to push Raw material details and search for it in blockchain.

Open https://remix.ethereum.org/

in your browser. Click on symbol located on top left side of the window. Write file name as Manufacturing_RM.sol and click on OK.

<img width="789" height="141" class="alignnone wp-image-185" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/102-1024x183.png" />

Copy past below code in Code window

pragma solidity ^0.4.18;

contract manufacturing_RM_Contract {

address owner;

struct Raw_Material

{

string PartNumber;

uint Quantity;

string Supplier;

}

mapping (string =&gt; Raw_Material) Raw_Materials;

address[] public Address_Raw_MaterialsAccts;

string[] public Raw_MaterialsAccts;

function setRaw_Material(address _creater,  string  _PartNumber, uint  _Quantity, string  _Supplier) public {

var RM = Raw_Materials[_PartNumber];

RM.PartNumber=_PartNumber;

RM.Quantity=_Quantity;

RM.Supplier=_Supplier;

Address_Raw_MaterialsAccts.push(_creater) -1;

}

function getRaw_Materials() constant public returns (address[]) {

return Address_Raw_MaterialsAccts;

}

&nbsp;

function getRaw_Materials(string _PartNumber) constant public returns (string,uint,string ) {

return (Raw_Materials[_PartNumber].PartNumber,Raw_Materials[_PartNumber].Quantity,

Raw_Materials[_PartNumber].Supplier);

}

function countRaw_Materialss() constant public returns (uint) {

return Address_Raw_MaterialsAccts.length;

}

}

&nbsp;

In Above code snippet, we have 1 struct with name “Raw_Material”. Which holds basic information of raw material like PartNumber, Quantity and Supplier details. You can add more details as per your requirements.

Remix will auto compile the code if you have selected “Auto Compile” else click on <img width="154" height="38" class="alignnone wp-image-195" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/114.png" /> to compile you code. Now we will deploy this smart contract in Ethereum Consortium Blockchain, which we had created in Step 1.

&nbsp;

<strong>Step 3: Deploy smart contracts on azure ethereum consortium blockchain</strong>

To deploy smart contract, we will use Remix only. In remix browser click on “Run” tab, which is located on top right side of screen

<img width="453" height="42" class="alignnone wp-image-205" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/123.png" />

From “Environment” drop down select “Web3 Provider”. It will show a pop up like shown below.

<img width="834" height="127" class="alignnone wp-image-215" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/133-1024x156.png" />

Click on OK. Now you need to provide “Web3 Provider Endpoint” for you Ethereum blockchain network. It is the “ethereum-rpc-endpoint”  value which we had saved from Azure portal as part of step1. Paste this value in popup window and click on “OK”.

<img width="815" height="144" class="alignnone wp-image-225" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/143-1024x181.png" />

Now It will show you some values in “Account” dropdown, which was earlier blank. Now we have connected remix IDE with in Ethereum Consortium Blockchain. Lets deploy smart contract. Click on “Create”

<img width="496" height="368" class="alignnone wp-image-235" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/153-1024x761.png" />

Now it will show 1 Pending transaction.

<img width="538" height="92" class="alignnone wp-image-245" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/163-1024x175.png" />

It will take few minutes to deploy contract and returns address on contact and interface for contract functions. It will look like

<img width="627" height="472" class="alignnone wp-image-255" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/171-1024x770.png" />

And in you console window you can see details on transaction. If you want to get more information, Click on “Details” button.

<img width="893" height="82" class="alignnone wp-image-265" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/181-1024x94.png" />

Now it’s time to test our smart contract.  First, we will test “setRaw_Material” function. In our contact this function accepts 4 inputs, address on transaction creator, part Number, quantity and Supplier details. You can get address on creator from “Accounts” drop down. Click on Copy icon  next to Accounts dropdown.

There is a textbox next to “setRaw_Material” button. Write your inputs in same text box. It will be something like below.

"&lt;AccountAddress&gt;", "Tyre",4,"Supplier1"

Replace &lt;AccountAddress&gt; with the value you had copied from “Accounts” drop down. Now click on “setRat_Metrial” button. <img width="391" height="58" class="alignnone wp-image-275" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/19.png" />

In console window It will return Block number and few details about transaction once it’s done.

<img width="907" height="93" class="alignnone wp-image-285" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/20-1024x105.png" />

Now Let’s try to get details on transaction which we had inserted in our Blockchain network.

Click on “countRaw_Materialss” button. It will return count 1, as we had inserted only 1 Raw material detail

<img width="394" height="60" class="alignnone wp-image-295" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/211.png" />

Let’s try to execute another function “getRaw_Materials”. In input box type “Tyre” and click on “getRaw_Materials “ button. It will show you all values that you had inserted using “setRaw_Material” function.

<img width="590" height="150" class="alignnone wp-image-305" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/03/221-1024x260.png" />

<strong>Recap:</strong>

We had created a ethereum consortium blockchain on Azure. Then we wrote a smart contract using remix. We deployed smart contract on our ethereum consortium blockchain. Finally, we were able to test it successfully.]]></content:encoded>
    </item>
    <item>
      <title>Handling High volume events with Azure Event hub</title>
      <link>https://docs.microsoft.com/archive/blogs/reenusaluja/handling-high-volume-events-with-azure-event-hub</link>
      <pubDate>Sat, 11 Nov 2017 09:41:43 GMT</pubDate>
      <dc:creator><![CDATA[ReenuSaluja]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/reenusaluja/?p=35</guid>
      <description><![CDATA[When we need to handle high volume events and telemetry per second, Azure Event hub service is an...]]></description>
      <content:encoded><![CDATA[When we need to handle high volume events and telemetry per second, <a target="_blank" href="https://azure.microsoft.com/en-in/services/event-hubs/" rel="noopener">Azure Event hub</a> service is an ideal candidate for this kind of workload. Azure Event Hub is a highly scalable data streaming platform and event ingestion service, capable of receiving and processing millions of events per second.

It is our first step for event pipeline, which we called event ingestor. It is a component between your event producer and event consumer. To handle millions of events per second, you can use multiple event hubs under a event hub namespace Also, in each event hub, we can have multiple partitions. At very high level, it will look as shown below

<img width="605" height="521" class="alignnone wp-image-45" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/11/fig-1.gif" />

Let’s next explore how we can use Azure event hub to handle high volume. At high level, we have 3 steps:
<ul>
 	<li>Configure Azure Event Hub service</li>
 	<li>Write service to push data into different partitions of Azure event hubs</li>
 	<li>Write service to Read data concurrently from different partitions of event hubs</li>
</ul>
<strong>Step 1 : Configure Azure Event Hub</strong>

To start with, we will create one event hub namespace with name “Eventhub-namespace-azure”.  Create this name space with default throughput unit i.e. 2. Under this event hub name space create 2 event hubs with name “hub1” and “hub2”. By default, each event hub has 2 partitions. Change number of partitions to 4 in both event hubs i.e. “hub1” and “hub2”. This is feasible only while creating the event hub. In Azure portal, it will look as shown below

<img width="1024" height="431" class="alignnone size-large wp-image-46" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/11/Fig-2-1024x431.png" />

Once you have created event hub you can’t modify number of partitions. For how to create event hub, refer below link

<a target="_blank" href="https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-create" rel="noopener">https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-create</a>

Now we are ready to push data into event hub. Let’s move to step 2.

<strong>Step 2 : Write service to push data into different partitions of event hubs.</strong>

Java code for sending event into specific eventhub  partition is in below git location

<a target="_blank" href="https://github.com/ReenuSaluja/Azure-eventhub-multi-partition-send" rel="noopener">https://github.com/ReenuSaluja/Azure-eventhub-multi-partition-send</a>

To clone the code on local run below command on command prompt

Git clone <a target="_blank" href="https://github.com/ReenuSaluja/Azure-eventhub-multi-partition-send" rel="noopener">https://github.com/ReenuSaluja/Azure-eventhub-multi-partition-send</a>

In code, go to client.java file which is <strong>located</strong> under com.ms.eventhub package. Replace values of  ----ServiceBusNamespaceName----, ----EventHubName----, ----SharedAccessSignatureKeyName----, ----SharedAccessSignatureKey---- into below code s

namespaceName = "----ServiceBusNamespaceName-----";

eventHubName = "----EventHubName-----";

sasKeyName = "-----SharedAccessSignatureKeyName-----";

sasKey = "---SharedAccessSignatureKey----";

based on your eventhub configuration in azure. Based on step 1 configuration, value of namespaceName would be “Eventhub-namespace-azure”. If you want to send events into event hub “hub1” then value of eventHubName would be hub1 , otherwise hub2.  To send event to eventhub sendSync function is called.

ehClient.sendSync(sendEvent,"partion1");

All Events with Same partitionKey will land on the Same Partition. So all the events with partition key “partion1” will be in same partition. In next line there is another statement ehClient.sendSync(sendEvent,"partion2");

Here the partition key is specified as "partion2". So this event will land into second  partition. Point to be noted here is, although both events will be going into different partitions, but part of same event hub.

After running the sample code, goto Azure portal. Select your eventhub namespace-&gt;hub1 and click on Metrics.

<img width="1024" height="548" class="alignnone size-large wp-image-55" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/11/Fig-3-1024x548.png" />

&nbsp;

Based on sample code 2 messages were sent one in each partition.

<strong> </strong>

<strong>Step 3 :   Write service to Read data concurrently from different partitions of event hubs.</strong>

To get sample code to read data from event hub, either you can git clone it from below location

<a target="_blank" href="https://github.com/ReenuSaluja/Azure-event-hub-reader-multithreading" rel="noopener">https://github.com/ReenuSaluja/Azure-event-hub-reader-multithreading</a>

or you can git clone from

<a target="_blank" href="https://github.com/Azure/azure-event-hubs/tree/master/samples/Java/src/main/java/com/microsoft/azure/eventhubs/samples/Basic" rel="noopener">https://github.com/Azure/azure-event-hubs/tree/master/samples/Java/src/main/java/com/microsoft/azure/eventhubs/samples/Basic</a> and customize it for multithreading. For both ways you need to follow steps to create storage account for event hub as given in

<a target="_blank" href="https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/event-hubs/event-hubs-java-get-started-receive-eph.md" rel="noopener">https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/event-hubs/event-hubs-java-get-started-receive-eph.md</a> article.

If you open EventProcessorSample from  <a target="_blank" href="https://github.com/ReenuSaluja/Azure-event-hub-reader-multithreading" rel="noopener">https://github.com/ReenuSaluja/Azure-event-hub-reader-multithreading</a><strong>, </strong>you will find a variable with name ExecutorService. This variable is initlize with a constructor Executors.newWorkStealingPool(2). Number 2 is there number of concurrent thread. You can increase it as per your requirement. newWorkStealingPool is part of java 1.8. if you are using older version, you can simply use newFixedThreadPool constructor for multithreading. Now there will be 2 concurrent threads running on same eventhub.

<strong>Few points to be noted.</strong>
<ul>
 	<li>In this code we are using default consumer group. You can enable multiple consuming applications to each have a separate view of the event stream, and to read the stream independently at their own pace and with their own offsets. In your code you just need to replace "$Default" value of consumerGroupName with your consumer group name.</li>
 	<li>You can have upto 5 concurrent readers on a partition per consumer group</li>
 	<li>In EventProcessor.java file</li>
</ul>
context.checkpoint(data);

statement keeps track of reader current position in the event stream. This saves  current checkpoint into storage account with details of consumer group, event hub.

You can get more details on this from <a target="_blank" href="https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-features" rel="noopener">https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-features</a>.
<ul>
 	<li>For batch processing of event, you can use LinkedList of EventData. That will be pass as parameter in sender.sendSync.</li>
 	<li>If you want to have multiple instance of reader application,</li>
</ul>
o   Configure multiple partitions in event hub.

o   In Step 3, in reader code, change value of “Host1” as unique  for each instance of the reader, which is a parameter in EventProcessorHost constructor.

&nbsp;

<strong>Recap</strong>

To handle high volume events in Azure event hub, first we had configured eventhubs. Then we used java api to insert data into different partitions of eventhub. We then created multithreaded Java application to read data from eventhub partitions.]]></content:encoded>
    </item>
    <item>
      <title>Hello world!</title>
      <link>https://docs.microsoft.com/archive/blogs/reenusaluja/hello-world</link>
      <pubDate>Thu, 09 Nov 2017 07:45:03 GMT</pubDate>
      <dc:creator><![CDATA[BharathNalla]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/reenusaluja/?p=1</guid>
      <description><![CDATA[Welcome to Developer Network. This is your first post. Edit or delete it, then start blogging!]]></description>
      <content:encoded><![CDATA[Welcome to <a href="https://blogs.msdn.microsoft.com/">Developer Network</a>. This is your first post. Edit or delete it, then start blogging!]]></content:encoded>
    </item>
  </channel>
</rss>