1. 程式人生 > >Listen gRPC and HTTP requests on the same port

Listen gRPC and HTTP requests on the same port

Listen gRPC and HTTP requests on the same port

As I said before, I'm working on a great project called Teresa written in Golang that uses gRPC. To facilitate monitoring and health checks, we decided to expose a health check endpoint with HTTP standard protocol instead of gRPC, but how can we expose those services on the same port?

There is a great project called cmux that can help us like a charm. According to cmux documentation: cmux is a generic Go library to multiplex connections based on their payload. In other words, you create a common net.Listener and define some rules to route your requests to the right server.

Talk is cheap, so let's build a toy example to show cmux in action beginning with a gRPC handler:

Nothing special here, right? Now, a "ping-pong" HTTP handler:

Ok, now is the time to “up and running”. We’ll create the main listener, a new connection multiplexer (aka cmux instance), new listeners that accept only connections that respect some rules like protocol, headers, etc (under the hood, those listeners use the same main listener we had created before) and finally start our server.

Done! Now you can run both servers (gRPC and HTTP) on the same TCP port. You can check the complete example on Github.

There is another way to deal with gRPC and HTTP on the same port without a third party framework (like cmux), but it’s a subject to another post.

Do you remember the problem I described in my last post? Well, now it's solved, because I started to accept HTTP requests.

相關推薦

Listen gRPC and HTTP requests on the same port

Listen gRPC and HTTP requests on the same portAs I said before, I'm working on a great project called Teresa written in Golang that uses gRPC. To facilitat

Getting the design and development team on the same page!

What makes or breaks a product team?Strong design principles are one. A clear, effective roadmap is another. But one of the most important, yet overlooked,

HOW TO RUN YOUR WEB SERVER AND MQTT WEBSOCKETS BROKER ON THE SAME PORT

I was just asked how one can deploy a similar setup as the iot.eclipse.org MQTT sandbox, where MQTT over WebSockets is available on por

A practical ES6 guide on how to perform HTTP requests using the Fetch API

In this guide, I’ll show you how to use the Fetch API (ES6+) to perform HTTP requests to an REST API with some practical examples you’ll most likely encoun

Ask HN: How to get everyone on the same page (dashboards/data/analytics)?

Hi HN,Has anyone here worked at a company where everyone was on the same page regarding which dashboards/analytics tools to go to when looking for dashboar

異常A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same

在建立webview的另外一個地方呼叫webview載入網頁,出現異常: 11-10 13:40:49.793: W/WebView(3684): java.lang.Throwable: A WebView method was called on thread 'Ja

Install multiple instances of Reporting Services on the same computer (for use with Microsoft Dynami

You can install multiple instances of Microsoft SQL Server Reporting Services on the same computer. In this kind of deployment environment, each instance

[轉]The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

right clas rup b- row 添加按鈕 n) 1-1 自帶 完整錯誤信息: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"AS IS" AND ANY EXPRESS O

新建 jsp異常,The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

prop 選擇 library path per png class pro found   新項目,新建jsp頁面的時候報異常: Multiple annotations found at this line: - The superclass "java

【論文:麥克風陣列增強】Speech Enhancement Based on the General Transfer Function GSC and Postfiltering

res transient ice ges nal gen image 增強 reg 作者:桂。 時間:2017-06-06 16:10:47 鏈接:http://www.cnblogs.com/xingshansi/p/6951494.html 原文鏈接:http

eclipse更改workspace中出現The superclass "javax.servlet.http.HttpServlet" was not found on the Java----問題》》

win runtime cli 名稱 tail 一個 fig workspace found 第一步:那是因為在項目中沒有告訴它應該在哪個tomcat中運行,右擊項目名稱-----》build path--》configure path---->library--

The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

uil 路徑 next run library per 錯誤 https 取消 新建WEB項目出現如下錯誤,可以這樣來修正, The superclass "javax.servlet.http.HttpServlet" was not found on the Java

Count the consecutive zero bits (trailing) on the right with multiply and lookup

驗證 %d vol tip inf mat cit number failed 我在網上看到了一點神奇的代碼,用來計算一個數字末尾連續零的個數。 剛好我在優化一個I2C讀寫函數(只寫入I2C特定bit),覺得這個很有用。經過嘗試,確實沒問題。 下面我隆重介紹一下: Coun

eclipse - The superclass "javax.servlet.http.HttpServlet" was not found on the Java

https 技術分享 eclips vax logs let not super images eclipse - The superclass "javax.servlet.http.HttpServlet" was not found on th

Java學習-051-Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError

conf dep skip startup ots tin static lang 錯誤信息 錯誤信息:Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, pre

JavaWeb:報錯信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

服務器軟件 vax ini AC 信息 enc 點擊 let 選擇服務器 JavaWeb: 報錯信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 一般

[IDE - Eclipse] JSP報錯:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

引入 ips eclips size eclipse -i let details javax 是因為Eclipse的Web項目不自動引入相關jar包. Right Click on the Project ? Properties ? Project Facets. Yo

MyEclipse中,使用Maven新建web項目後,提示The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

web png -a ips cti code 使用 te pro ron 問題描述:   使用 MyEclipse + Maven 建立了一個 Javaweb工程,在編寫 JSP頁面 時,頂端出現“紅色”的報錯信息:The superclass

Eclipse中jsp異常 The superclass "javax.servlet.http.HttpServlet" was not found on the Java Bu

問題描述        學習ssh商城的時候,將資料中給的靜態檔案引入jsp資料夾,但是每個檔案都有一個大紅×,,然後在jsp檔案裡面出現了The superclass"javax.servlet.http.HttpServlet"

java錯誤:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

java錯誤:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path 我們在用Eclipse進行Java web開發時,可能會出現這樣的錯誤:The superclass j