azure-event-hubs-go
azure-event-hubs-go copied to clipboard
Cannot connect to Event Hub endpoint through proxy
Expected Behavior
I would expect to be able to send/receive data to/from the Event Hub endpoint when operating behind a proxy, but this does not appear to be supported.
I'd expect to see a WithProxy(...)
function of type HubOption
to be used when setting up a hub, for example:
rawConnStr := os.Getenv("EVENTHUB_CONNECTION_STRING")
if rawConnStr == "" {
fmt.Println("FATAL: expected environment variable EVENTHUB_CONNECTION_STRING not set")
return
}
hubName := os.Getenv("EVENTHUB_NAME")
if hubName == "" {
fmt.Println("FATAL: expected environment variable EVENTHUB_NAME not set")
return
}
httpProxy := os.Getenv("HTTP_PROXY")
if hubName == "" {
fmt.Println("FATAL: expected environment variable HTTP_PROXY not set")
return
}
connStr := rawConnStr + ";EntityPath=" + hubName
hub, err := eventhub.NewHubFromConnectionString(connStr, WithProxy(httpProxy))
if err != nil {
fmt.Println(err)
return
}
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
runtimeInfo, err := hub.GetRuntimeInformation(ctx)
if err != nil {
fmt.Println(err)
return
}
A WithAuthenticatedProxy(httpProxy, username, password)
option would also be useful for those behind a proxy which requires a username and password.
Actual Behavior
Without the option to provide a proxy configuration, I encounter the error:
dial tcp <event-hub-ip>:5671: connectex: No connection could be made because the target machine actively refused it.
Environment
- OS: Windows
- Go version: 1.13
- Version of Library: v3.1.2
I may be wrong, but you can do that for Java, thanks to https://github.com/Azure/azure-event-hubs-java/pull/362. Having said that, I've the same problem as @Bixx and I need to use filebeat to access Azure Event Hub from behind a corporate HTTP(S) proxy.
@Bixx how did you do that . in which version is kind of functionality available
You will need to use websockets to achieve this. Sample code is below:
func newWebSocketConnFn(ctx context.Context, args azeventhubs.WebSocketConnParams) (net.Conn, error) {
defaultTransport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
.
.
.
}
opts := &websocket.DialOptions{
Subprotocols: []string{"amqp"},
HTTPClient: &http.Client{
Transport: defaultTransport,
},
}
wssConn, _, err := websocket.Dial(ctx, args.Host, opts)
if err != nil {
return nil, err
}
return websocket.NetConn(ctx, wssConn, websocket.MessageBinary), nil
}
consumerClient, err := azeventhubs.NewConsumerClientFromConnectionString(nameSpaceConnectionString, eventhubName, consumerGroup, &azeventhubs.ConsumerClientOptions{
NewWebSocketConn: newWebSocketConnFn,
})
An example is provided here: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/messaging/azeventhubs/example_websockets_and_proxies_test.go#L32