由于每秒数据吞吐量巨大,需要将实时数据存到event hubs,再由event hubs定时定量保存到document DB。

event hubs的介绍详见微软官页:https://azure.microsoft.com/zh-tw/services/event-hubs/

事件中樞

從網站、應用程式和裝置擷取雲端等級的遙測數據

  • 幾乎每秒即時地記錄數百萬個事件
  • 使用靈活的授權與節流來連接裝置
  • 以時間為基礎處理事件緩衝
  • 利用彈性化的規模來管理服務
  • 使用原生用戶端程式庫連接廣泛的平台
  • 其他雲端服務隨插即用的配接器

每秒串流處理數百萬個事件

Azure 事件中樞是極具調整規模彈性的「發佈-訂閱」服務,其每秒可吸取上百萬項事件,並將這些事件串流至多項應用程式。如此可讓您處理及分析由所連接之裝置與應用程式所產生的大量資料。當事件中樞收集到資料之後,即可利用任何即時分析提供者或以批次/儲存裝置介面卡,來轉換及儲存資料。

處理具變動式負載數據來源的事件

現今的互聯世界即是由巨量資料所構成。巨量資料源自許多變動式負載數據來源,像是每隔幾分鐘即產生遙測資料的互聯車輛與控溫器、每秒產生事件的應用程式效能計數器,以及擷取每位使用者個別動作遙測資料的行動應用程式。事件中樞是一款受管理的服務,其能吸取規模具彈性的事件,以容納這些變動式負載數據來源以及由間歇連接所引發的尖峰情況。

跨平台連接數百萬個裝置

因為所連接的裝置種類成長快速,且涉及各種平台與通訊協定,所以讓吸取來自各種裝置的資料形成相當大的挑戰。而事件中樞不僅能處理各式規模的彙總串流,同時也可迎接這項連接不同資料來源的挑戰。事件中樞可輕鬆佈建容量,處理來自上百萬項裝置的事件,同時也能以裝置為單位維持事件順序。對進階訊息佇列通訊協定 (AMQP) 與 HTTP 所提供的支援,能讓許多平台皆可使用事件中樞。常見的平台也有原生用戶端程式庫可用。

 

定义event hubs:

private EventHubClientMapping _eventHubClient = new EventHubClientMapping();

保存:

  protected void SaveDomainUserToFile(DomainUser user, bool isReceive = false)
{
System.Runtime.Serialization.Json.DataContractJsonSerializer json =
new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(DomainUser)); json.WriteObject(stream, user);
stream.Write(_cn, , _cn.Length); byte[] bs = stream.ToArray();
String contentStr = System.Text.Encoding.UTF8.GetString(bs);
//Event Hub
try
{
Notify(contentStr);
}
catch (Exception ex)
{
throw ex;
} StartSave();
}

调用接口方法:

  public void Notify(string cookie)
{
_eventHubClient.AddMessage(cookie);
}

webconfig中要加入这两句:

 </configuration>
<appSettings>
<add key="MappingDataFlowEventHubConnection" value="Endpoint=sb://xxx.servicebus.chinacloudapi.cn/;SharedAccessKeyName=sender;SharedAccessKey=xxx;TransportType=Amqp"/>
<add key="MappingDataFlowEventHubName" value="mapping-response-eventhub" />
</appSettings>
</configuration>

azure cloud service上的配置:

继承的接口azure core中建立interface:

  public interface IMappingNotify
{
void Notify(string cookie);
} public class MappingNotify
{
public CookieSource CookieSource { get; set; } public string Company { get; set; } public string Domain { get; set; } public string IP { get; set; } public string Lang { get; set; } public string PUID { get; set; } public string Refer { get; set; } public string ScreenHeight { get; set; } public string ScreenWidth { get; set; } public string TimeStamp { get; set; } public string Title { get; set; } public string UA { get; set; } public string UID { get; set; } public string URL { get; set; } public string Version { get; set; } public static byte[] Serialize(string cookie)
{
var message = string.Format("{0}", cookie); return Encoding.UTF8.GetBytes(message);
} public static IList<MappingNotify> Deserialize(byte[] message)
{
if (message == null || message.Length == )
throw new Exception("message is null."); var mns = new List<MappingNotify>(); var str = Encoding.UTF8.GetString(message);
string[] jsons = str.Trim('\n').Trim('\r').Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string json in jsons)
{
var jObject = JObject.Parse(json); var mn = new MappingNotify(); if (jObject["company"] != null)
mn.Company = jObject["company"].ToString();
if (jObject["domain"] != null)
mn.Domain = jObject["domain"].ToString();
if (jObject["ip"] != null)
mn.IP = jObject["ip"].ToString();
if (jObject["lang"] != null)
mn.Lang = jObject["lang"].ToString();
if (jObject["puid"] != null)
mn.PUID = jObject["puid"].ToString();
if (jObject["refer"] != null)
mn.Refer = jObject["refer"].ToString();
if (jObject["screenHeight"] != null)
mn.ScreenHeight = jObject["screenHeight"].ToString();
if (jObject["screenWidth"] != null)
mn.ScreenWidth = jObject["screenWidth"].ToString();
if (jObject["timestamp"] != null)
mn.TimeStamp = jObject["timestamp"].ToString();
if (jObject["title"] != null)
mn.Title = jObject["title"].ToString();
if (jObject["ua"] != null)
mn.UA = jObject["ua"].ToString();
if (jObject["uid"] != null)
mn.UID = jObject["uid"].ToString();
if (jObject["url"] != null)
mn.URL = jObject["url"].ToString();
if (jObject["version"] != null)
mn.Version = jObject["version"].ToString(); mn.CookieSource = CookieSource.mapping; mns.Add(mn);
} return mns;
}
}

在azure cloud service上的configuration文件加上这两句:

 <ConfigurationSettings>
<Setting name="MappingDataFlowEventHubConnection" value="Endpoint=sb://xxx.servicebus.chinacloudapi.cn/;SharedAccessKeyName=sender;SharedAccessKey=xxx;TransportType=Amqp"/>
<Setting name="MappingDataFlowEventHubName" value="mapping-response-eventhub" />
</ConfigurationSettings>

在azure business中加入一个cs文件:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.Composition; using xxx.Core.Interface;
using xxx.Core.Entity;
using xxx.Core;
using xxx.Core.Client; namespace xxx.Business
{
[Export(typeof(IMappingNotify))]
public class EventHubMappingNotify : IMappingNotify
{
private EventHubClientMapping _eventHubClient = new EventHubClientMapping(); public void Notify(string cookie)
{
_eventHubClient.AddMessage(cookie);
}
} }

在azure core中config.cs文件中加入config信息:

 //EventHub链接
public static string MappingDataFlowEventHubConnection
{
get
{
var config = CloudConfigurationManager.GetSetting("MappingDataFlowEventHubConnection");
if (string.IsNullOrEmpty(config))
throw new Exception("MappingDataFlowEventHubConnection hasn't configured!"); return config;
}
}

EventHub链接

 //EventHub存储配置
public static string MappingDataFlowEventHubName
{
get
{
var config = CloudConfigurationManager.GetSetting("MappingDataFlowEventHubName");
if (string.IsNullOrEmpty(config))
{
return "mapping-response-eventhub";
} return config;
}
}

EventHub存储配置

 //EventHub消费者组
public static string MappingDataFlowEventHubConsumer
{
get
{
var config = CloudConfigurationManager.GetSetting("MappingDataFlowEventHubConsumer");
if (string.IsNullOrEmpty(config))
throw new Exception("MappingDataFlowEventHubConsumer hasn't configured!"); return config;
}
}

EventHub消费者组

在azure core中加入client.cs文件:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using Microsoft.Azure;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging; using xxx.Core.Entity;
using xxx.Core;
using xxx.Core.Interface; namespace xxx.Core.Client
{
public class EventHubClientMapping
{
private Microsoft.ServiceBus.Messaging.EventHubClient _eventHubClient; public EventHubClientMapping()
{
var factory = MessagingFactory.CreateFromConnectionString(DANDaasConfig.MappingDataFlowEventHubConnection);
_eventHubClient = factory.CreateEventHubClient(DANDaasConfig.MappingDataFlowEventHubName); _eventHubClient.RetryPolicy = RetryPolicy.Default;
} public void AddMessage(string cookie)
{
var message = new EventData(MappingNotify.Serialize(cookie)); _eventHubClient.Send(message);
}
} }

额。。差不多了。。

第一次将内容添加到azure event hubs的更多相关文章

  1. 微软公有云事件中心(Azure Event Hubs)在开放物联网大会(OIOT)啼声初试

     发布于 2014-12-29 作者 刘 天栋 2014年12月18日,InfoQ在京召开开放物联网大会(Open IOT Conference),微软开放技术(中国)资深项目经理陈岭在大会中针对 ...

  2. 【Azure 事件中心】在微软云中国区 (Mooncake) 上实验以Apache Kafka协议方式发送/接受Event Hubs消息 (Java版)

    问题描述 事件中心提供 Kafka 终结点,现有的基于 Kafka 的应用程序可将该终结点用作运行你自己的 Kafka 群集的替代方案. 事件中心可与许多现有 Kafka 应用程序配合使用.在Azur ...

  3. Azure Event Hub 技术研究系列2-发送事件到Event Hub

    上篇博文中,我们介绍了Azure Event Hub的一些基本概念和架构: Azure Event Hub 技术研究系列1-Event Hub入门篇 本篇文章中,我们继续深入研究,了解Azure Ev ...

  4. Azure Event Hub 技术研究系列3-Event Hub接收事件

    上篇博文中,我们通过编程的方式介绍了如何将事件消息发送到Azure Event Hub: Azure Event Hub 技术研究系列2-发送事件到Event Hub 本篇文章中,我们继续:从Even ...

  5. 【事件中心 Azure Event Hub】在Linux环境中(Ubuntu)安装Logstash的简易步骤及配置连接到Event Hub

    在文章([事件中心 Azure Event Hub]使用Logstash消费EventHub中的event时遇见的几种异常(TimeoutException, ReceiverDisconnected ...

  6. 【Azure 事件中心】Azure Event Hub 新功能尝试 -- 异地灾难恢复 (Geo-Disaster Recovery)

    问题描述 关于Event Hub(事件中心)的灾备方案,大多数就是新建另外一个备用的Event Hub,当主Event Hub出现不可用的情况时,就需要切换到备Event Hub上. 而在切换的过程中 ...

  7. [Azure] Notification Hubs注册模式

    [Azure] Notification Hubs注册模式 关于Azure Notification Hubs的注册模式,可以参考下列连结的文件内容. Notification Hubs Featur ...

  8. Azure Event Bus 技术研究系列1-Event Hub入门篇

    前两个系列研究了Azure IoT Hub和Azure Messaging.最近准备继续研究Azure Event Bus,即Azure的事件中心.首先, Azure Event Hub的官方介绍: ...

  9. Azure Event Hub 技术研究系列1-Event Hub入门篇

    前两个系列研究了Azure IoT Hub和Azure Messaging.最近准备继续研究Azure Event Hub,即Azure的事件中心.首先, Azure Event Hub的官方介绍: ...

随机推荐

  1. 细说IIS异常日志 — 你必须知道的功能

    最近在跟QAD用Webservice搞接口做数据维护,搞的哥那个叫头大,遇到很多问题,系统的log4net根本就无法记录.话说QAD调我某一个接口,可能包含几百个字段,而且QAD是个产品,所以我这边提 ...

  2. Linux学习四:UDP编程(上)

    关于UDP和TCP对比优缺,这里就不说了. 使用UDP代码所掉用的函数和用于TCP的函数非常类似,这主要因为套接口库在底层的TCP和UDP的函数上加了一层抽象,通过这层抽象使得编程更容易,但失去了一些 ...

  3. 谈谈Java面向对象的三大特性

    Java面向对象的三大特性就是指封装.继承.多态了. 一.封装: 概念:封装是指隐藏对象的属性和实现细节,仅对外提供公共访问方式. (举例:笔记本电脑就是一个封装体,Java语言中最小的封装体就是函数 ...

  4. backprop示例

    http://home.agh.edu.pl/~vlsi/AI/backp_t_en/backprop.html

  5. 2015.05.12:json的常用处理方式

    1:json的介绍:json常用于前台与后台的数据传输  传递时需将json对象转换为json字符 JSON.stringify(); 2:json格式的查看应用:JsonView 3:后台获取到js ...

  6. linux 进程的创建

    1. 进程号: 每个进程在被初始化的时候,系统都会为其分配一个唯一标识的进程id,称为进程号: 进程号的类型为pid_t,通过getpid()和getppid()可以获取当前进程号和当前进程的父进程的 ...

  7. 2016-11-10:win7下VMware虚拟机中CentOS6.5网络配置

    在win7环境下,使用桥接和NAT模式配置VMware虚拟机网络,实现宿主机与虚拟机以及虚拟机通过宿主机网卡访问互联网. 1 配置VMware虚拟网络编辑器 VMnet0 桥接模式 VMnet1仅主机 ...

  8. Android IOS WebRTC 音视频开发总结(八十二)-- VP8对VP9,质量还是码率?

    本文主要介绍VP9(我们翻译和整理的,译者:weizhenwei,校验:blacker),最早发表在[编风网] 支持原创,转载必须注明出处,欢迎关注我的微信公众号blacker(微信ID:blacke ...

  9. 逻辑运算符&&和&的区别 ||和|的区别

    A:最终结果一样. B:&& 和 || 有短路作用,左边是false ,右边不执行.

  10. Geometry Stage in Rendering pipeline (读书笔记2 --- Real-Time rendering)

    Geometry Stage一般包含下面几个阶段 1. Model & View Transform(模型和视图变换) --- 模型空间--> 世界空间 模型变换:每个模型经过模型变换来 ...