Files

249 lines
11 KiB
TypeScript

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* This sample demonstrates how to Creates an input or replaces an already existing input under an existing streaming job.
*
* @summary Creates an input or replaces an already existing input under an existing streaming job.
* x-ms-original-file: specification/streamanalytics/resource-manager/Microsoft.StreamAnalytics/preview/2021-10-01-preview/examples/Input_Create_GatewayMessageBus.json
*/
import type { Input } from "@azure/arm-streamanalytics";
import { StreamAnalyticsManagementClient } from "@azure/arm-streamanalytics";
import { DefaultAzureCredential } from "@azure/identity";
import "dotenv/config";
async function createAGatewayMessageBusInput(): Promise<void> {
const subscriptionId =
process.env["STREAMANALYTICS_SUBSCRIPTION_ID"] || "56b5e0a9-b645-407d-99b0-c64f86013e3d";
const resourceGroupName = process.env["STREAMANALYTICS_RESOURCE_GROUP"] || "sjrg3467";
const jobName = "sj9742";
const inputName = "input7970";
const input: Input = {
properties: {
type: "Stream",
datasource: { type: "GatewayMessageBus", topic: "EdgeTopic1" },
},
};
const credential = new DefaultAzureCredential();
const client = new StreamAnalyticsManagementClient(credential, subscriptionId);
const result = await client.inputs.createOrReplace(resourceGroupName, jobName, inputName, input);
console.log(result);
}
/**
* This sample demonstrates how to Creates an input or replaces an already existing input under an existing streaming job.
*
* @summary Creates an input or replaces an already existing input under an existing streaming job.
* x-ms-original-file: specification/streamanalytics/resource-manager/Microsoft.StreamAnalytics/preview/2021-10-01-preview/examples/Input_Create_Reference_Blob_CSV.json
*/
async function createAReferenceBlobInputWithCsvSerialization(): Promise<void> {
const subscriptionId =
process.env["STREAMANALYTICS_SUBSCRIPTION_ID"] || "56b5e0a9-b645-407d-99b0-c64f86013e3d";
const resourceGroupName = process.env["STREAMANALYTICS_RESOURCE_GROUP"] || "sjrg8440";
const jobName = "sj9597";
const inputName = "input7225";
const input: Input = {
properties: {
type: "Reference",
datasource: {
type: "Microsoft.Storage/Blob",
blobName: "myblobinput",
container: "state",
dateFormat: "yyyy/MM/dd",
deltaPathPattern: "/testBlob/{date}/delta/{time}/",
deltaSnapshotRefreshRate: "16:14:30",
fullSnapshotRefreshRate: "16:14:30",
pathPattern: "{date}/{time}",
sourcePartitionCount: 16,
storageAccounts: [{ accountKey: "someAccountKey==", accountName: "someAccountName" }],
timeFormat: "HH",
},
serialization: { type: "Csv", encoding: "UTF8", fieldDelimiter: "," },
},
};
const credential = new DefaultAzureCredential();
const client = new StreamAnalyticsManagementClient(credential, subscriptionId);
const result = await client.inputs.createOrReplace(resourceGroupName, jobName, inputName, input);
console.log(result);
}
/**
* This sample demonstrates how to Creates an input or replaces an already existing input under an existing streaming job.
*
* @summary Creates an input or replaces an already existing input under an existing streaming job.
* x-ms-original-file: specification/streamanalytics/resource-manager/Microsoft.StreamAnalytics/preview/2021-10-01-preview/examples/Input_Create_Reference_File.json
*/
async function createAReferenceFileInput(): Promise<void> {
const subscriptionId =
process.env["STREAMANALYTICS_SUBSCRIPTION_ID"] || "56b5e0a9-b645-407d-99b0-c64f86013e3d";
const resourceGroupName = process.env["STREAMANALYTICS_RESOURCE_GROUP"] || "sjrg8440";
const jobName = "sj9597";
const inputName = "input7225";
const input: Input = {
properties: {
type: "Reference",
datasource: { type: "File", path: "my/path" },
},
};
const credential = new DefaultAzureCredential();
const client = new StreamAnalyticsManagementClient(credential, subscriptionId);
const result = await client.inputs.createOrReplace(resourceGroupName, jobName, inputName, input);
console.log(result);
}
/**
* This sample demonstrates how to Creates an input or replaces an already existing input under an existing streaming job.
*
* @summary Creates an input or replaces an already existing input under an existing streaming job.
* x-ms-original-file: specification/streamanalytics/resource-manager/Microsoft.StreamAnalytics/preview/2021-10-01-preview/examples/Input_Create_Stream_EventHub_JSON.json
*/
async function createAStreamEventHubInputWithJsonSerialization(): Promise<void> {
const subscriptionId =
process.env["STREAMANALYTICS_SUBSCRIPTION_ID"] || "56b5e0a9-b645-407d-99b0-c64f86013e3d";
const resourceGroupName = process.env["STREAMANALYTICS_RESOURCE_GROUP"] || "sjrg3139";
const jobName = "sj197";
const inputName = "input7425";
const input: Input = {
properties: {
type: "Stream",
datasource: {
type: "Microsoft.ServiceBus/EventHub",
consumerGroupName: "sdkconsumergroup",
eventHubName: "sdkeventhub",
serviceBusNamespace: "sdktest",
sharedAccessPolicyKey: "someSharedAccessPolicyKey==",
sharedAccessPolicyName: "RootManageSharedAccessKey",
},
serialization: { type: "Json", encoding: "UTF8" },
watermarkSettings: { watermarkMode: "ReadWatermark" },
},
};
const credential = new DefaultAzureCredential();
const client = new StreamAnalyticsManagementClient(credential, subscriptionId);
const result = await client.inputs.createOrReplace(resourceGroupName, jobName, inputName, input);
console.log(result);
}
/**
* This sample demonstrates how to Creates an input or replaces an already existing input under an existing streaming job.
*
* @summary Creates an input or replaces an already existing input under an existing streaming job.
* x-ms-original-file: specification/streamanalytics/resource-manager/Microsoft.StreamAnalytics/preview/2021-10-01-preview/examples/Input_Create_Stream_IoTHub_Avro.json
*/
async function createAStreamIoTHubInputWithAvroSerialization(): Promise<void> {
const subscriptionId =
process.env["STREAMANALYTICS_SUBSCRIPTION_ID"] || "56b5e0a9-b645-407d-99b0-c64f86013e3d";
const resourceGroupName = process.env["STREAMANALYTICS_RESOURCE_GROUP"] || "sjrg3467";
const jobName = "sj9742";
const inputName = "input7970";
const input: Input = {
properties: {
type: "Stream",
datasource: {
type: "Microsoft.Devices/IotHubs",
consumerGroupName: "sdkconsumergroup",
endpoint: "messages/events",
iotHubNamespace: "iothub",
sharedAccessPolicyKey: "sharedAccessPolicyKey=",
sharedAccessPolicyName: "owner",
},
serialization: { type: "Avro" },
},
};
const credential = new DefaultAzureCredential();
const client = new StreamAnalyticsManagementClient(credential, subscriptionId);
const result = await client.inputs.createOrReplace(resourceGroupName, jobName, inputName, input);
console.log(result);
}
/**
* This sample demonstrates how to Creates an input or replaces an already existing input under an existing streaming job.
*
* @summary Creates an input or replaces an already existing input under an existing streaming job.
* x-ms-original-file: specification/streamanalytics/resource-manager/Microsoft.StreamAnalytics/preview/2021-10-01-preview/examples/Input_Create_Stream_Blob_CSV.json
*/
async function createAStreamBlobInputWithCsvSerialization(): Promise<void> {
const subscriptionId =
process.env["STREAMANALYTICS_SUBSCRIPTION_ID"] || "56b5e0a9-b645-407d-99b0-c64f86013e3d";
const resourceGroupName = process.env["STREAMANALYTICS_RESOURCE_GROUP"] || "sjrg8161";
const jobName = "sj6695";
const inputName = "input8899";
const input: Input = {
properties: {
type: "Stream",
datasource: {
type: "Microsoft.Storage/Blob",
container: "state",
dateFormat: "yyyy/MM/dd",
pathPattern: "{date}/{time}",
sourcePartitionCount: 16,
storageAccounts: [{ accountKey: "someAccountKey==", accountName: "someAccountName" }],
timeFormat: "HH",
},
serialization: { type: "Csv", encoding: "UTF8", fieldDelimiter: "," },
},
};
const credential = new DefaultAzureCredential();
const client = new StreamAnalyticsManagementClient(credential, subscriptionId);
const result = await client.inputs.createOrReplace(resourceGroupName, jobName, inputName, input);
console.log(result);
}
/**
* This sample demonstrates how to Creates an input or replaces an already existing input under an existing streaming job.
*
* @summary Creates an input or replaces an already existing input under an existing streaming job.
* x-ms-original-file: specification/streamanalytics/resource-manager/Microsoft.StreamAnalytics/preview/2021-10-01-preview/examples/Input_Create_EventGrid.json
*/
async function createAnEventGridInput(): Promise<void> {
const subscriptionId =
process.env["STREAMANALYTICS_SUBSCRIPTION_ID"] || "56b5e0a9-b645-407d-99b0-c64f86013e3d";
const resourceGroupName = process.env["STREAMANALYTICS_RESOURCE_GROUP"] || "sjrg3467";
const jobName = "sj9742";
const inputName = "input7970";
const input: Input = {
properties: {
type: "Stream",
datasource: {
type: "Microsoft.EventGrid/EventSubscriptions",
schema: "CloudEventSchema",
eventTypes: ["Microsoft.Storage.BlobCreated"],
storageAccounts: [
{
accountKey: "myaccountkey",
accountName: "myaccount",
authenticationMode: "Msi",
},
],
subscriber: {
type: "Microsoft.EventHub/EventHub",
authenticationMode: "Msi",
consumerGroupName: "sdkconsumergroup",
eventHubName: "sdkeventhub",
partitionCount: 16,
serviceBusNamespace: "sdktest",
sharedAccessPolicyKey: "someSharedAccessPolicyKey==",
sharedAccessPolicyName: "RootManageSharedAccessKey",
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new StreamAnalyticsManagementClient(credential, subscriptionId);
const result = await client.inputs.createOrReplace(resourceGroupName, jobName, inputName, input);
console.log(result);
}
async function main(): Promise<void> {
await createAGatewayMessageBusInput();
await createAReferenceBlobInputWithCsvSerialization();
await createAReferenceFileInput();
await createAStreamEventHubInputWithJsonSerialization();
await createAStreamIoTHubInputWithAvroSerialization();
await createAStreamBlobInputWithCsvSerialization();
await createAnEventGridInput();
}
main().catch(console.error);