AzureFunctions + AzureStorage + AzureDocumentDB로 데이터 Import2
우리 팀은 올 퍼블릭 클라우드에서 Microservice Architecture을 채택한 차기 백엔드를 설계 중입니다.
경위
지난번 의 투고로 json을 Blob 컨테이너에 준비했으므로, 이번은 그것을 받아들여, 1문서씩 Servicebus에 publish한다. 또한 다른 기능으로 그것을 subscribe하고 DocumentDB에 store합니다.
json:testLines.json{ "original_id" : "1", "b":false , "c":0 , "d":1 , "e":2 , "f":0.345 , "g":"あ" , "h":"い" }
{ "original_id" : "2", "b":false , "c":0 , "d":1 , "e":2 , "f":0.345 , "g":"あ" , "h":"い" }
{ "original_id" : "3", "b":false , "c":0 , "d":1 , "e":2 , "f":0.345 , "g":"あ" , "h":"い" }
servicebus 준비

topic는 창조해 둔다.
AzureFunctions(publish)
이번에는 언어는 C#으로 간다. 이유는 제일 할 수 있는 것이 많으니까. 그 이유로 가면,
선택은 C#, js, F#일까.
통합

당연히 input은 blob, output은 DocumentDB.
NuGet
파일을 1행 1행 읽는 것은 좋지만, 그것을 1건씩 퍼스한다.
편하게 치퍼하기 위하여 이번에는 J손. 뿌리 T를 사용한다. NuGet에서 install한다.

왼쪽 하단의 Functions APP 설정에서 AppService 편집기로 이동.

project.json을 만듭니다.
project.json{
"frameworks": {
"net46":{
"dependencies": {
"Newtonsoft.Json": "9.0.1"
}
}
}
}
project.lock.json이 자동으로 생성됩니다.
이것으로 install 완료.
개발
using System.IO;
using System.Text;
using Newtonsoft.Json;
public static void Run(string myBlob, string name, Stream inputBlob, ICollector<string> outputSbMsg, TraceWriter log)
{
log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
StreamReader reader = new StreamReader(inputBlob, Encoding.UTF8);
string line;
while ((line = reader.ReadLine()) != null)
{
Item item = JsonConvert.DeserializeObject<Item>(line);
string id = item.Id;
if (String.IsNullOrEmpty(id)) {
outputSbMsg.Add(line);
}
else {
log.Info("can't accept id.");
}
}
reader.Close();
}
public class Item
{
[JsonProperty("id")]
public string Id { get; set; }
}
AzureFunctions(subscribe)
이쪽은 꽤 간단
통합

개발
using System;
using System.Threading.Tasks;
public static void Run(string mySbMsg, out object outputDocument, TraceWriter log)
{
// log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
outputDocument = mySbMsg;
}
다음 번
이상으로 Blob의 컨텐츠 트리거로 DocumentDB에의 보존까지가 완료.
Servicebus의 topic을 통해서 있으므로, subscriber를 새롭게 늘림으로써 같은 데이터가 브로드캐스트되는 이점은 있다.
다음은 MachineLearning과 연계해 본다.
Reference
이 문제에 관하여(AzureFunctions + AzureStorage + AzureDocumentDB로 데이터 Import2), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tstakano-yj/items/c7b609750dc9171442bd
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
{ "original_id" : "1", "b":false , "c":0 , "d":1 , "e":2 , "f":0.345 , "g":"あ" , "h":"い" }
{ "original_id" : "2", "b":false , "c":0 , "d":1 , "e":2 , "f":0.345 , "g":"あ" , "h":"い" }
{ "original_id" : "3", "b":false , "c":0 , "d":1 , "e":2 , "f":0.345 , "g":"あ" , "h":"い" }

topic는 창조해 둔다.
AzureFunctions(publish)
이번에는 언어는 C#으로 간다. 이유는 제일 할 수 있는 것이 많으니까. 그 이유로 가면,
선택은 C#, js, F#일까.
통합

당연히 input은 blob, output은 DocumentDB.
NuGet
파일을 1행 1행 읽는 것은 좋지만, 그것을 1건씩 퍼스한다.
편하게 치퍼하기 위하여 이번에는 J손. 뿌리 T를 사용한다. NuGet에서 install한다.

왼쪽 하단의 Functions APP 설정에서 AppService 편집기로 이동.

project.json을 만듭니다.
project.json{
"frameworks": {
"net46":{
"dependencies": {
"Newtonsoft.Json": "9.0.1"
}
}
}
}
project.lock.json이 자동으로 생성됩니다.
이것으로 install 완료.
개발
using System.IO;
using System.Text;
using Newtonsoft.Json;
public static void Run(string myBlob, string name, Stream inputBlob, ICollector<string> outputSbMsg, TraceWriter log)
{
log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
StreamReader reader = new StreamReader(inputBlob, Encoding.UTF8);
string line;
while ((line = reader.ReadLine()) != null)
{
Item item = JsonConvert.DeserializeObject<Item>(line);
string id = item.Id;
if (String.IsNullOrEmpty(id)) {
outputSbMsg.Add(line);
}
else {
log.Info("can't accept id.");
}
}
reader.Close();
}
public class Item
{
[JsonProperty("id")]
public string Id { get; set; }
}
AzureFunctions(subscribe)
이쪽은 꽤 간단
통합

개발
using System;
using System.Threading.Tasks;
public static void Run(string mySbMsg, out object outputDocument, TraceWriter log)
{
// log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
outputDocument = mySbMsg;
}
다음 번
이상으로 Blob의 컨텐츠 트리거로 DocumentDB에의 보존까지가 완료.
Servicebus의 topic을 통해서 있으므로, subscriber를 새롭게 늘림으로써 같은 데이터가 브로드캐스트되는 이점은 있다.
다음은 MachineLearning과 연계해 본다.
Reference
이 문제에 관하여(AzureFunctions + AzureStorage + AzureDocumentDB로 데이터 Import2), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tstakano-yj/items/c7b609750dc9171442bd
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
{
"frameworks": {
"net46":{
"dependencies": {
"Newtonsoft.Json": "9.0.1"
}
}
}
}
using System.IO;
using System.Text;
using Newtonsoft.Json;
public static void Run(string myBlob, string name, Stream inputBlob, ICollector<string> outputSbMsg, TraceWriter log)
{
log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
StreamReader reader = new StreamReader(inputBlob, Encoding.UTF8);
string line;
while ((line = reader.ReadLine()) != null)
{
Item item = JsonConvert.DeserializeObject<Item>(line);
string id = item.Id;
if (String.IsNullOrEmpty(id)) {
outputSbMsg.Add(line);
}
else {
log.Info("can't accept id.");
}
}
reader.Close();
}
public class Item
{
[JsonProperty("id")]
public string Id { get; set; }
}
이쪽은 꽤 간단
통합

개발
using System;
using System.Threading.Tasks;
public static void Run(string mySbMsg, out object outputDocument, TraceWriter log)
{
// log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
outputDocument = mySbMsg;
}
다음 번
이상으로 Blob의 컨텐츠 트리거로 DocumentDB에의 보존까지가 완료.
Servicebus의 topic을 통해서 있으므로, subscriber를 새롭게 늘림으로써 같은 데이터가 브로드캐스트되는 이점은 있다.
다음은 MachineLearning과 연계해 본다.
Reference
이 문제에 관하여(AzureFunctions + AzureStorage + AzureDocumentDB로 데이터 Import2), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tstakano-yj/items/c7b609750dc9171442bd
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(AzureFunctions + AzureStorage + AzureDocumentDB로 데이터 Import2), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/tstakano-yj/items/c7b609750dc9171442bd텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)