• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang consumer.Consumer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cloudfoundry/noaa/consumer.Consumer的典型用法代码示例。如果您正苦于以下问题:Golang Consumer类的具体用法?Golang Consumer怎么用?Golang Consumer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Consumer类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1:

	"github.com/cloudfoundry/noaa/consumer"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/elazarl/goproxy"
	"github.com/elazarl/goproxy/ext/auth"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Consumer connecting through a Proxy", func() {
	var (
		connection *consumer.Consumer

		messagesToSend chan []byte
		testServer     *httptest.Server
		endpoint       string
		proxy          func(*http.Request) (*url.URL, error)

		testProxyServer *httptest.Server
		goProxyHandler  *goproxy.ProxyHttpServer
	)

	BeforeEach(func() {
		messagesToSend = make(chan []byte, 256)
		testServer = httptest.NewServer(handlers.NewWebsocketHandler(messagesToSend, 100*time.Millisecond, loggertesthelper.Logger()))
		endpoint = "ws://" + testServer.Listener.Addr().String()

		goProxyHandler = goproxy.NewProxyHttpServer()
		goProxyHandler.Logger = log.New(bytes.NewBufferString(""), "", 0)
		testProxyServer = httptest.NewServer(goProxyHandler)
		proxy = func(*http.Request) (*url.URL, error) {
开发者ID:cloudfoundry,项目名称:v3-cli-plugin,代码行数:31,代码来源:consumer_proxy_test.go


示例2: ServeHTTP

type nullHandler chan struct{}

func (h nullHandler) ServeHTTP(http.ResponseWriter, *http.Request) {
	<-h
}

const (
	appGuid     = "fakeAppGuid"
	authToken   = "fakeAuthToken"
	testTimeout = 1 * time.Second
)

var (
	cnsmr       *consumer.Consumer
	testServer  *httptest.Server
	fakeHandler nullHandler
)

var _ = Describe("Timeout", func() {
	AfterSuite(func() {
		if testServer != nil {
			testServer.Close()
		}
	})

	BeforeEach(func() {
		internal.Timeout = testTimeout

		fakeHandler = make(nullHandler, 1)
		testServer = httptest.NewServer(fakeHandler)
开发者ID:cloudfoundry,项目名称:v3-cli-plugin,代码行数:30,代码来源:timeout_test.go


示例3:

	"github.com/cloudfoundry/noaa/consumer"
	"github.com/cloudfoundry/noaa/test_helpers"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/gogo/protobuf/proto"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Consumer (Asynchronous)", func() {
	var (
		cnsmr                *consumer.Consumer
		trafficControllerURL string
		testServer           *httptest.Server
		fakeHandler          *test_helpers.FakeHandler
		tlsSettings          *tls.Config

		appGuid        string
		authToken      string
		messagesToSend chan []byte
	)

	BeforeEach(func() {
		trafficControllerURL = ""
		testServer = nil
		fakeHandler = nil
		tlsSettings = nil

		appGuid = ""
		authToken = ""
		messagesToSend = make(chan []byte, 256)
开发者ID:cloudfoundry,项目名称:v3-cli-plugin,代码行数:31,代码来源:async_test.go


示例4:

	"time"

	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
	"github.com/cloudfoundry/loggregatorlib/server/handlers"
	"github.com/cloudfoundry/noaa/consumer"

	. "github.com/apoydence/eachers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("RefreshTokenFrom", func() {
	Context("Asynchronous", func() {
		var (
			cnsmr       *consumer.Consumer
			testHandler *errorRespondingHandler
			tcURL       string
			refresher   *mockTokenRefresher
		)

		BeforeEach(func() {
			testHandler = &errorRespondingHandler{
				subHandler:       handlers.NewWebsocketHandler(make(chan []byte), 100*time.Millisecond, loggertesthelper.Logger()),
				responseStatuses: make(chan int, 10),
			}
			server := httptest.NewServer(testHandler)
			tcURL = "ws://" + server.Listener.Addr().String()

			refresher = newMockTokenRefresher()
			cnsmr = consumer.New(tcURL, nil, nil)

			cnsmr.RefreshTokenFrom(refresher)
开发者ID:cloudfoundry,项目名称:v3-cli-plugin,代码行数:32,代码来源:token_refresher_test.go


示例5:

			BeforeEach(func() {
				count = 100
			})

			JustBeforeEach(func() {
				for i := 0; i < count; i++ {
					time.Sleep(10 * time.Millisecond)
					helpers.EmitToMetron(buildValueMetric("mainValue", float64(i)))
				}
			})

			Context("single connection", func() {
				var (
					reader *consumer.Consumer
					msgs   <-chan *events.Envelope
					errs   <-chan error
				)

				JustBeforeEach(func() {
					go emitControlMessages()
					waitForControl(msgs)
				})

				BeforeEach(func() {
					reader, _ = helpers.SetUpConsumer()
					msgs, errs = reader.Firehose(generateSubID(), "")
					go readFromErrors(errs)
				})

				AfterEach(func() {
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:30,代码来源:firehose_test.go


示例6:

		Expect(err).ToNot(HaveOccurred())
		Expect(testFile.Close()).To(Succeed())

		testContents = func() string {
			contents, err := ioutil.ReadFile(accessLogFile)
			Expect(err).ToNot(HaveOccurred())
			return string(contents)
		}
	})

	AfterEach(func() {
		Expect(os.Remove(accessLogFile)).To(Succeed())
	})

	Context("with modern endpoints", func() {
		var noaaConsumer *consumer.Consumer

		JustBeforeEach(func() {
			tcURL := fmt.Sprintf("ws://%s:%d", localIPAddress, TRAFFIC_CONTROLLER_DROPSONDE_PORT)
			noaaConsumer = consumer.New(tcURL, &tls.Config{}, nil)
		})

		AfterEach(func() {
			noaaConsumer.Close()
		})

		It("logs stream access", func() {
			noaaConsumer.Stream(APP_ID, AUTH_TOKEN)

			expected := fmt.Sprintf("CEF:0|cloud_foundry|loggregator_trafficcontroller|1.0|GET /apps/%s/stream|GET /apps/%[1]s/stream|0|", APP_ID)
			Eventually(testContents).Should(ContainSubstring(expected))
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:31,代码来源:accesslog_end_to_end_test.go


示例7:

	var dropsondeEndpoint string

	BeforeEach(func() {
		fakeDoppler = fake_doppler.New()
		go fakeDoppler.Start()
		dropsondeEndpoint = fmt.Sprintf("ws://%s:%d", localIPAddress, TRAFFIC_CONTROLLER_DROPSONDE_PORT)
	})

	AfterEach(func() {
		fakeDoppler.Stop()
	})

	Context("Streaming", func() {
		var (
			client   *consumer.Consumer
			messages <-chan *events.Envelope
			errors   <-chan error
		)

		JustBeforeEach(func() {
			client = consumer.New(dropsondeEndpoint, &tls.Config{}, nil)
			messages, errors = client.StreamWithoutReconnect(APP_ID, AUTH_TOKEN)
		})

		It("passes messages through", func() {
			var request *http.Request
			Eventually(fakeDoppler.TrafficControllerConnected, 10).Should(Receive(&request))
			Expect(request.URL.Path).To(Equal("/apps/1234/stream"))

			currentTime := time.Now().UnixNano()
			dropsondeMessage := makeDropsondeMessage("Hello through NOAA", APP_ID, currentTime)
开发者ID:yingkitw,项目名称:loggregator,代码行数:31,代码来源:dropsonde_end_to_end_test.go



注:本文中的github.com/cloudfoundry/noaa/consumer.Consumer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errors.NewUnauthorizedError函数代码示例发布时间:2022-05-23
下一篇:
Golang consumer.New函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap