This blog is part of IoT Series, where I am trying to build few IoT devices that push events to Azure EventHub. From the EventHub, Azure Stream Analytics will execute my query to calculate average values for each individual device and publish these average values to Azure ServiceBus. From Azure ServiceBus, I am going to read the average values in Azure Functions Apps and save them into Azure Redis Cache. My Azure Website will poll this Redis Cache and displays the average values.
Here are list of blog posts in this series:
- Azure IoT
- Azure EventHub–sending IoT device events to EventHub
- Azure ServiceBus Queue–reading query results from Stream Analytics
- Azure Stream Analytics–reading events from EventHub, running query and saving results to ServiceBus
- Azure Function Apps – reading events from ServiceBus and writing to Redis Cache
In this blog, I am going to show how to configure Azure Function Apps to read from Azure ServiceBus and write them to Azure Redis Cache.
- Log into Azure Portal
- Click on + New button
- In the Search, type Function App
- Select Function App and provide name, resource group, storage account as shown below
- Click on Create button
- Once the Function App is deployed, browse to newly created Function App
- In the Function App, click on the + New Function
- In the templates, select ServiceBusQueueTrigger – C# as shown below
- Now we need to add ServiceBus Connection String
- Click on new link next to the Service Bus Connection as shown below
- Provide the connection string name and connection string to Azure Service Bus. Click here to learn how to get connection string.
- Expand function and click on Develop node as shown
- Enter below code in the run.csx file
using System;
using System.Threading.Tasks;
using StackExchange.Redis;
using Newtonsoft.Json;public static void Run(string myQueueItem, TraceWriter log)
{
log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");var msg = JsonConvert.DeserializeObject<MyOutput>(myQueueItem);
if (msg == null)
{
log.Info("failed to convert msg to MyOutput");
return;
}IDatabase cache = Connection.GetDatabase();
cache.StringSet(msg.devicename, myQueueItem);
}private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect("redis connection string");
});public static ConnectionMultiplexer Connection
{
get
{
return lazyConnection.Value;
}
}class MyOutput
{public string devicename { get; set; }
public double avgtemp { get; set; }
public double avgspeed { get; set; }
} - Now we need to add NuGet package for Newtonsoft and Redis Cache
- Click on the View files and click + to add a new file
- Set the name of the new file as Project.json and add these lines
{
"frameworks": {
"net46": {
"dependencies": {
"StackExchange.Redis":"1.1.603",
"Newtonsoft.Json": "9.0.1"
}
}
}
} - Now try to run the Function, click on the Run button in the Run section as shown below
- Check for any compiler errors in the above Logs section
- next, push few events into EventHub using the console app, code is here
- These events will travel from EventHub to Stream Analytics to Service Bus Queue to Function App to Redis Cache
- To verify if the event reached Redis Cache, in the Azure Portal, navigate to Redis Cache and click on Console and execute these commands as shown
There is noticeably a bundle to know about this. I assume you made certain good factors in options also.
LikeLike
I am sure this post has touched all the internet visitors, its really really fastidious paragraph on building up new web site.
LikeLike
Wonderful site you have here but I was curious if you knew of any message boards that cover the same topics
discussed in this article? I’d really love to be a part of
community where I can get opinions from other knowledgeable individuals that share the same interest.
If you have any recommendations, please let me know.
Cheers!
LikeLike
Great read. Thanks mate
LikeLike
I absolutely love your blog.. Pleasant colors & theme.
Did you create this amazing site yourself? Please reply back as I’m planning to create my own personal site and would love to learn where you got this from or
what the theme is named. Cheers!
LikeLike
Thank you.
I am using this theme : http://www.andersnoren.se/teman/baskerville-wordpress-theme/
LikeLike
Do you have any video of that? I’d like too find out more details.
LikeLike
i like your article.
LikeLike
I cannot thank you enough for the blog post.Really looking forward to read more. Awesome.
LikeLike
Say, you got a nice blog post.Thanks Again.
LikeLike
Say, you got a nice blog post.Thanks Again.
LikeLike
I cannot thank you enough for the blog post.Really looking forward to read more. Awesome.
LikeLike
This is a topic which is close to my heart… Many thanks! Exactly where are your contact details though?
LikeLike
Hey there! Do you use Twitter? I’d like to follow you if that would be okay. I’m absolutely enjoying your blog and look forward to new posts.|
LikeLike
There is definately a great deal to know about this topic.
LikeLike
Thank you for your blog article.Really looking forward to read more. Will read on…
LikeLike
I have read so many articles concerning the blogger lovers except this post is in fact a pleasant post, keep it up.|
LikeLike
Keep this going please, great job!|
LikeLike
I absolutely love your blog and find the majority of your post’s to be exactly I’m looking for. Do you offer guest writers to write content available for you? I wouldn’t mind creating a post or elaborating on many of the subjects you write about here. Again, awesome web log!|
LikeLike
I’m no longer sure where you are getting your information, however good topic. I must spend a while finding out more or understanding more. Thank you for fantastic info I was looking for this information for my mission.
LikeLike
Attractive element of content. I simply stumbled upon your weblog and in accession capital to assert that I acquire in fact loved account your weblog posts. Anyway I will be subscribing on your feeds and even I achievement you access consistently fast.|
LikeLike
I think other website proprietors should take this site as an model, very clean and excellent user genial style and design, let alone the content. You are an expert in this topic!
LikeLike
You have brought up a very excellent points , appreciate it for the post.
LikeLike
thank you web sites.
LikeLike
Hey there! I just wish to offer you a huge thumbs up for your excellent information you’ve got right here on this post. I will be coming back to your site for more soon.|
LikeLike
Hi there! I’m at work surfing around your blog from my new iphone! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the great work!|
LikeLike
It’s actually a cool and useful piece of information. I am happy that you just shared this helpful information with us. Please keep us informed like this. Thanks for sharing.
LikeLike
Hello just wanted to give you a quick heads up and let you know a few of the images aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and both show the same results.
LikeLike
I love this, thank you!!!
LikeLike
Your method of describing everything in this piece of writing is actually fastidious, every one be able to simply know it, Thanks a lot.|
LikeLike
It’s actually a nice and useful piece of info. I’m glad that you just shared this useful information with us. Please stay us up to date like this. Thanks for sharing.
LikeLike
Great info. Lucky me I discovered your site by chance (stumbleupon). I’ve book marked it for later!
LikeLike
I don’t know whether it’s just me or if everyone else experiencing issues with your website. It seems like some of the written text within your content are running off the screen. Can somebody else please comment and let me know if this is happening to them too? This might be a problem with my browser because I’ve had this happen previously. Many thanks
LikeLike
Have you ever considered publishing an ebook or guest authoring on other sites? I have a blog based on the same ideas you discuss and would really like to have you share some stories/information. I know my subscribers would enjoy your work. If you’re even remotely interested, feel free to shoot me an e mail.
LikeLike
Hi would you mind letting me know which hosting company you’re using? I’ve loaded your blog in 3 completely different internet browsers and I must say this blog loads a lot quicker then most. Can you suggest a good web hosting provider at a fair price? Thanks a lot, I appreciate it!|
LikeLike
Hey there, I think your blog might be having browser compatibility issues. When I look at your blog in Firefox, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, very good blog!|
LikeLike
It’s nearly impossible to find experienced people for this subject, however, you seem like you know what you’re talking about! Thanks
LikeLike