Skip to content

Commit d17638f

Browse files
[azeventhubs] Initial import of source from azure-event-hubs-go (Azure#18234)
Starting initial source import, with our standard procedure: - Move all public surface into 'internal' - Change all imports - Clear out any root level files that aren't ready or shouldn't be present in in a module in the monorepo Note, there are no code changes beyond the simple changes needed to make it compile (which included fixing a few small lint errors).
1 parent a90c4a7 commit d17638f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+9492
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release History
2+
3+
## 0.1.0 (TBD)
4+
5+
- Initial preview for the new version of the Azure Event Hubs Go SDK.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) Microsoft Corporation.
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

sdk/messaging/azeventhubs/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file.
2+
trigger:
3+
branches:
4+
include:
5+
- main
6+
- feature/*
7+
- hotfix/*
8+
- release/*
9+
paths:
10+
include:
11+
- sdk/messaging/azeventhubs
12+
13+
pr:
14+
branches:
15+
include:
16+
- main
17+
- feature/*
18+
- hotfix/*
19+
- release/*
20+
paths:
21+
include:
22+
- sdk/messaging/azeventhubs
23+
24+
stages:
25+
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
26+
parameters:
27+
ServiceDirectory: 'messaging/azeventhubs'
28+
# (live tests not yet ready to run)
29+
# RunLiveTests: true
30+
SupportedClouds: 'Public,UsGov,China'
31+
EnvVars:
32+
AZURE_CLIENT_ID: $(AZEVENTHUBS_CLIENT_ID)
33+
AZURE_TENANT_ID: $(AZEVENTHUBS_TENANT_ID)
34+
AZURE_CLIENT_SECRET: $(AZEVENTHUBS_CLIENT_SECRET)
35+
AZURE_SUBSCRIPTION_ID: $(AZEVENTHUBS_SUBSCRIPTION_ID)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package azservicebus

sdk/messaging/azeventhubs/go.mod

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventhubs
2+
3+
go 1.18
4+
5+
require (
6+
github.com/Azure/azure-amqp-common-go/v3 v3.2.3
7+
github.com/Azure/azure-pipeline-go v0.1.9
8+
github.com/Azure/azure-sdk-for-go v51.1.0+incompatible
9+
github.com/Azure/azure-storage-blob-go v0.6.0
10+
github.com/Azure/go-amqp v0.17.0
11+
github.com/Azure/go-autorest/autorest v0.11.18
12+
github.com/Azure/go-autorest/autorest/adal v0.9.13
13+
github.com/Azure/go-autorest/autorest/azure/auth v0.4.2
14+
github.com/Azure/go-autorest/autorest/date v0.3.0
15+
github.com/Azure/go-autorest/autorest/to v0.4.0
16+
github.com/devigned/tab v0.1.1
17+
github.com/joho/godotenv v1.3.0
18+
github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7
19+
github.com/mitchellh/mapstructure v1.1.2
20+
github.com/sirupsen/logrus v1.2.0
21+
github.com/stretchr/testify v1.6.1
22+
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
23+
)
24+
25+
require (
26+
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
27+
github.com/Azure/go-autorest/autorest/azure/cli v0.3.1 // indirect
28+
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
29+
github.com/Azure/go-autorest/logger v0.2.1 // indirect
30+
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
31+
github.com/davecgh/go-spew v1.1.1 // indirect
32+
github.com/dimchansky/utfbom v1.1.0 // indirect
33+
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
34+
github.com/google/go-cmp v0.5.3 // indirect
35+
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
36+
github.com/mitchellh/go-homedir v1.1.0 // indirect
37+
github.com/pkg/errors v0.9.1 // indirect
38+
github.com/pmezard/go-difflib v1.0.0 // indirect
39+
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
40+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
41+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
42+
)

sdk/messaging/azeventhubs/go.sum

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
github.com/Azure/azure-amqp-common-go/v3 v3.2.3 h1:uDF62mbd9bypXWi19V1bN5NZEO84JqgmI5G73ibAmrk=
2+
github.com/Azure/azure-amqp-common-go/v3 v3.2.3/go.mod h1:7rPmbSfszeovxGfc5fSAXE4ehlXQZHpMja2OtxC2Tas=
3+
github.com/Azure/azure-pipeline-go v0.1.8/go.mod h1:XA1kFWRVhSK+KNFiOhfv83Fv8L9achrP7OxIzeTn1Yg=
4+
github.com/Azure/azure-pipeline-go v0.1.9 h1:u7JFb9fFTE6Y/j8ae2VK33ePrRqJqoCM/IWkQdAZ+rg=
5+
github.com/Azure/azure-pipeline-go v0.1.9/go.mod h1:XA1kFWRVhSK+KNFiOhfv83Fv8L9achrP7OxIzeTn1Yg=
6+
github.com/Azure/azure-sdk-for-go v51.1.0+incompatible h1:7uk6GWtUqKg6weLv2dbKnzwb0ml1Qn70AdtRccZ543w=
7+
github.com/Azure/azure-sdk-for-go v51.1.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
8+
github.com/Azure/azure-storage-blob-go v0.6.0 h1:SEATKb3LIHcaSIX+E6/K4kJpwfuozFEsmt5rS56N6CE=
9+
github.com/Azure/azure-storage-blob-go v0.6.0/go.mod h1:oGfmITT1V6x//CswqY2gtAHND+xIP64/qL7a5QJix0Y=
10+
github.com/Azure/go-amqp v0.17.0 h1:HHXa3149nKrI0IZwyM7DRcRy5810t9ZICDutn4BYzj4=
11+
github.com/Azure/go-amqp v0.17.0/go.mod h1:9YJ3RhxRT1gquYnzpZO1vcYMMpAdJT+QEg6fwmw9Zlg=
12+
github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs=
13+
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
14+
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
15+
github.com/Azure/go-autorest/autorest v0.9.3/go.mod h1:GsRuLYvwzLjjjRoWEIyMUaYq8GNUx2nRB378IPt/1p0=
16+
github.com/Azure/go-autorest/autorest v0.11.18 h1:90Y4srNYrwOtAgVo3ndrQkTYn6kf1Eg/AjTFJ8Is2aM=
17+
github.com/Azure/go-autorest/autorest v0.11.18/go.mod h1:dSiJPy22c3u0OtOKDNttNgqpNFY/GeWa7GH/Pz56QRA=
18+
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
19+
github.com/Azure/go-autorest/autorest/adal v0.8.0/go.mod h1:Z6vX6WXXuyieHAXwMj0S6HY6e6wcHn37qQMBQlvY3lc=
20+
github.com/Azure/go-autorest/autorest/adal v0.8.1/go.mod h1:ZjhuQClTqx435SRJ2iMlOxPYt3d2C/T/7TiQCVZSn3Q=
21+
github.com/Azure/go-autorest/autorest/adal v0.9.13 h1:Mp5hbtOePIzM8pJVRa3YLrWWmZtoxRXqUEzCfJt3+/Q=
22+
github.com/Azure/go-autorest/autorest/adal v0.9.13/go.mod h1:W/MM4U6nLxnIskrw4UwWzlHfGjwUS50aOsc/I3yuU8M=
23+
github.com/Azure/go-autorest/autorest/azure/auth v0.4.2 h1:iM6UAvjR97ZIeR93qTcwpKNMpV+/FTWjwEbuPD495Tk=
24+
github.com/Azure/go-autorest/autorest/azure/auth v0.4.2/go.mod h1:90gmfKdlmKgfjUpnCEpOJzsUEjrWDSLwHIG73tSXddM=
25+
github.com/Azure/go-autorest/autorest/azure/cli v0.3.1 h1:LXl088ZQlP0SBppGFsRZonW6hSvwgL5gRByMbvUbx8U=
26+
github.com/Azure/go-autorest/autorest/azure/cli v0.3.1/go.mod h1:ZG5p860J94/0kI9mNJVoIoLgXcirM2gF5i2kWloofxw=
27+
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
28+
github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g=
29+
github.com/Azure/go-autorest/autorest/date v0.3.0 h1:7gUk1U5M/CQbp9WoqinNzJar+8KY+LPI6wiWrP/myHw=
30+
github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74=
31+
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
32+
github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
33+
github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM=
34+
github.com/Azure/go-autorest/autorest/mocks v0.4.1 h1:K0laFcLE6VLTOwNgSxaGbUcLPuGXlNkbVvq4cW4nIHk=
35+
github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k=
36+
github.com/Azure/go-autorest/autorest/to v0.4.0 h1:oXVqrxakqqV1UZdSazDOPOLvOIz+XA683u8EctwboHk=
37+
github.com/Azure/go-autorest/autorest/to v0.4.0/go.mod h1:fE8iZBn7LQR7zH/9XU2NcPR4o9jEImooCeWJcYV/zLE=
38+
github.com/Azure/go-autorest/autorest/validation v0.3.1 h1:AgyqjAd94fwNAoTjl/WQXg4VvFeRFpO+UhNyRXqF1ac=
39+
github.com/Azure/go-autorest/autorest/validation v0.3.1/go.mod h1:yhLgjC0Wda5DYXl6JAsWyUe4KVNffhoDhG0zVzUMo3E=
40+
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
41+
github.com/Azure/go-autorest/logger v0.2.1 h1:IG7i4p/mDa2Ce4TRyAO8IHnVhAVF3RFU+ZtXWSmf4Tg=
42+
github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8=
43+
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
44+
github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo=
45+
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
46+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
47+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
48+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
49+
github.com/devigned/tab v0.1.1 h1:3mD6Kb1mUOYeLpJvTVSDwSg5ZsfSxfvxGRTxRsJsITA=
50+
github.com/devigned/tab v0.1.1/go.mod h1:XG9mPq0dFghrYvoBF3xdRrJzSTX1b7IQrvaL9mzjeJY=
51+
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
52+
github.com/dimchansky/utfbom v1.1.0 h1:FcM3g+nofKgUteL8dm/UpdRXNC9KmADgTpLKsu0TRo4=
53+
github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8=
54+
github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk=
55+
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
56+
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
57+
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
58+
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
59+
github.com/google/go-cmp v0.5.3 h1:x95R7cp+rSeeqAMI2knLtQ0DKlaBhv2NrtrOvafPHRo=
60+
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
61+
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
62+
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
63+
github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7 h1:K//n/AqR5HjG3qxbrBCL4vJPW0MVFSs9CPK1OOJdRME=
64+
github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7/go.mod h1:2iMrUgbbvHEiQClaW2NsSzMyGHqN+rDFqY705q49KG0=
65+
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
66+
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
67+
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
68+
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
69+
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
70+
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
71+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
72+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
73+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
74+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
75+
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
76+
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
77+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
78+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
79+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
80+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
81+
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
82+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
83+
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
84+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
85+
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
86+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
87+
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE=
88+
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
89+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
90+
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
91+
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
92+
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
93+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
94+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
95+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
96+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
97+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
98+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
99+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
100+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
101+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
102+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
103+
gopkg.in/check.v1 v1.0.0-20161208181325-20d25e280405 h1:829vOVxxusYHC+IqBtkX5mbKtsY9fheQiQn0MZRVLfQ=
104+
gopkg.in/check.v1 v1.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
105+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
106+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Batch Processing
2+
3+
To process batches of events at one time a handler needs to implement both an event handler function as well as the `CheckpointPersister` interface.
4+
5+
## Running this example
6+
7+
Set the following environment variables `EVENTHUB_PARTITIONID`, `EVENTHUB_CONSUMERGROUP`, `EVENTHUB_NAMESPACE`, `EVENTHUB_NAME`, `EVENTHUB_KEY_NAME` and `EVENTHUB_KEY_VALUE` and run the executable.
8+
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package main
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"io"
10+
11+
eventhub "github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventhubs/internal"
12+
"github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventhubs/internal/persist"
13+
)
14+
15+
type persistRecord struct {
16+
namespace string
17+
name string
18+
consumerGroup string
19+
partitionID string
20+
checkpoint persist.Checkpoint
21+
}
22+
23+
type batchWriter struct {
24+
persister persist.CheckpointPersister
25+
writer io.Writer
26+
27+
batchSize int
28+
batch []string
29+
persistRecords []*persistRecord
30+
flushed *persistRecord
31+
}
32+
33+
var batchSize = 10
34+
35+
// NewBatchWriter creates an object that can be used as both a `persist.CheckpointPersister` and an Event Hubs Event Handler `batchWriter.HandleEvent`
36+
func NewBatchWriter(persister persist.CheckpointPersister, writer io.Writer) (*batchWriter, error) {
37+
return &batchWriter{
38+
persister: persister,
39+
writer: writer,
40+
batchSize: batchSize,
41+
batch: make([]string, 0, batchSize),
42+
persistRecords: make([]*persistRecord, 0, batchSize),
43+
}, nil
44+
}
45+
46+
// Read reads the last checkpoint
47+
func (w batchWriter) Read(namespace, name, consumerGroup, partitionID string) (persist.Checkpoint, error) {
48+
return w.persister.Read(namespace, name, consumerGroup, partitionID)
49+
}
50+
51+
// Write will write the last checkpoint of the last event flushed and record persist records for future use
52+
func (w *batchWriter) Write(namespace, name, consumerGroup, partitionID string, checkpoint persist.Checkpoint) error {
53+
var err error
54+
if w.flushed != nil {
55+
r := w.flushed
56+
err = w.persister.Write(r.namespace, r.name, r.consumerGroup, r.partitionID, r.checkpoint)
57+
if err != nil {
58+
w.flushed = nil
59+
}
60+
}
61+
w.persistRecords = append(w.persistRecords, &persistRecord{
62+
namespace: namespace,
63+
name: name,
64+
consumerGroup: consumerGroup,
65+
partitionID: partitionID,
66+
checkpoint: checkpoint,
67+
})
68+
return err
69+
}
70+
71+
// HandleEvent will handle Event Hubs Events
72+
// If the length of the batch buffer has reached the max batchSize, the buffer will be flushed before appending the new event
73+
// If flush fails and it hasn't made space in the buffer, the flush error will be returned to the caller
74+
func (w *batchWriter) HandleEvent(ctx context.Context, event *eventhub.Event) error {
75+
if len(w.batch) >= batchSize {
76+
err := w.Flush(ctx)
77+
// If we received an error flushing and still don't have room in the buffer return the error
78+
if err != nil && len(w.batch) >= batchSize {
79+
return err
80+
}
81+
}
82+
// Append the event to the buffer if we have room for it
83+
w.batch = append(w.batch, string(event.Data))
84+
return nil
85+
}
86+
87+
// Flush flushes the buffer to the given io.Writer
88+
// Post-condition:
89+
// error == nil: buffer has been flushed successfully, buffer has been replaced with a new buffer
90+
// error != nil: some or no events have been flushed, buffer contains only events that failed to flush
91+
func (w *batchWriter) Flush(ctx context.Context) error {
92+
for i, s := range w.batch {
93+
_, err := fmt.Fprintln(w.writer, s)
94+
if err != nil {
95+
w.batch = w.batch[i:]
96+
w.persistRecords = w.persistRecords[i:]
97+
return err
98+
}
99+
w.flushed = w.persistRecords[i]
100+
}
101+
w.batch = make([]string, 0, batchSize)
102+
w.persistRecords = make([]*persistRecord, 0, batchSize)
103+
return nil
104+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package main
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"os"
10+
"os/signal"
11+
"strings"
12+
13+
eventhub "github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventhubs/internal"
14+
"github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventhubs/internal/persist"
15+
)
16+
17+
func main() {
18+
ctx := context.Background()
19+
20+
fp, err := persist.NewFilePersister(os.Getenv("EVENTHUB_FILEPERSIST_DIRECTORY"))
21+
if err != nil {
22+
fmt.Println(err.Error())
23+
os.Exit(1)
24+
}
25+
26+
output, err := NewBatchWriter(fp, os.Stdout)
27+
if err != nil {
28+
fmt.Println(err.Error())
29+
os.Exit(1)
30+
}
31+
32+
hub, err := eventhub.NewHubFromEnvironment(eventhub.HubWithOffsetPersistence(output))
33+
if err != nil {
34+
fmt.Println(err.Error())
35+
os.Exit(1)
36+
}
37+
defer hub.Close(ctx)
38+
39+
partitionId := os.Getenv("EVENTHUB_PARTITIONID")
40+
if partitionId == "" {
41+
parts := strings.SplitN(os.Getenv("HOSTNAME"), "-", 2)
42+
if len(parts) == 2 {
43+
partitionId = parts[1]
44+
} else {
45+
fmt.Println("EVENTHUB_PARTITIONID environment variable must be set")
46+
os.Exit(1)
47+
}
48+
}
49+
50+
consumerGroup := os.Getenv("EVENTHUB_CONSUMERGROUP")
51+
if consumerGroup == "" {
52+
consumerGroup = "$Default"
53+
}
54+
55+
_, err = hub.Receive(ctx, partitionId, output.HandleEvent, eventhub.ReceiveWithConsumerGroup(consumerGroup), eventhub.ReceiveWithPrefetchCount(20000))
56+
if err != nil {
57+
fmt.Println(err.Error())
58+
os.Exit(1)
59+
}
60+
61+
signalChan := make(chan os.Signal, 1)
62+
signal.Notify(signalChan, os.Interrupt, os.Kill)
63+
<-signalChan
64+
}

0 commit comments

Comments
 (0)