Alanxtl opened a new issue, #3359:
URL: https://github.com/apache/dubbo-go/issues/3359
## Title
REST application-level service discovery requires importing Dubbo protocol
to fetch metadata
## Problem
A REST consumer using application-level service discovery fails unless it
also imports the Dubbo protocol extension:
```go
_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
```
Without this import, the consumer panics:
```text
panic: protocol for [dubbo] is not existing
```
This is surprising because the user-facing service protocol is REST. The
Dubbo protocol is only used internally by the service discovery path to call
`org.apache.dubbo.metadata.MetadataService`.
## Minimal Reproduction
There is currently no ready-made REST service-discovery sample in the
repository, so this was reproduced with a small local REST provider/consumer
sample.
### 1. Shared REST mapping
Create a REST service with one method:
- interface: `org.apache.dubbo.samples.rest.GreetingService`
- method: `GetGreeting`
- REST path: `POST /api/v1/users/{userID}/greeting`
- args:
- arg 0 -> path param `userID`
- arg 1 -> query param `name`
- arg 2 -> header `X-Trace-ID`
- arg 3 -> JSON body
Both provider and consumer install the same REST method config through:
```go
restconfig.SetRestProviderServiceConfigMap(...)
restconfig.SetRestConsumerServiceConfigMap(...)
```
### 2. Provider setup
The provider is configured as a REST service and uses application-level
registration:
```go
ins, err := dubbo.NewInstance(
dubbo.WithName("dubbo_rest_basic_server"),
dubbo.WithProtocol(
protocol.WithREST(),
protocol.WithIp("127.0.0.1"),
protocol.WithPort(20080),
),
dubbo.WithRegistry(
registry.WithZookeeper(),
registry.WithAddress("127.0.0.1:2181"),
registry.WithoutUseAsConfigCenter(),
registry.WithRegisterService(),
),
)
```
Then register the REST service:
```go
srv, _ := ins.NewServer()
err = srv.RegisterService(
&GreetingProvider{},
dubboserver.WithInterface("org.apache.dubbo.samples.rest.GreetingService"),
)
err = srv.Serve()
```
Required provider imports include REST protocol, registry protocol, service
discovery, metadata mapping/report, and ZooKeeper registry.
### 3. Consumer setup that fails
The consumer also uses application-level service discovery:
```go
ins, err := dubbo.NewInstance(
dubbo.WithName("dubbo_rest_basic_client"),
dubbo.WithRegistry(
registry.WithZookeeper(),
registry.WithAddress("127.0.0.1:2181"),
registry.WithoutUseAsConfigCenter(),
registry.WithRegisterService(),
),
)
cli, err := ins.NewClient(client.WithClientNoCheck())
conn, err := cli.Dial(
"org.apache.dubbo.samples.rest.GreetingService",
client.WithProtocol(constant.RESTProtocol),
)
```
The consumer imports REST protocol and service discovery related packages,
but intentionally does **not** import Dubbo protocol:
```go
_ "dubbo.apache.org/dubbo-go/v3/protocol/rest"
_ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
_ "dubbo.apache.org/dubbo-go/v3/registry/servicediscovery"
_ "dubbo.apache.org/dubbo-go/v3/registry/directory"
_ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper"
_ "dubbo.apache.org/dubbo-go/v3/metadata/mapping/metadata"
_ "dubbo.apache.org/dubbo-go/v3/metadata/report/zookeeper"
```
Run:
```bash
go run ./server
go run ./client
```
The consumer fails with:
```text
panic: protocol for [dubbo] is not existing
```
### 4. Workaround
Adding this import to the REST consumer fixes the issue:
```go
_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
```
After that, the REST call succeeds. The consumer discovers the provider
application, fetches metadata through:
```text
dubbo://127.0.0.1:<metadata-port>/org.apache.dubbo.metadata.MetadataService
```
and reconstructs a REST provider URL like:
```text
rest://127.0.0.1:20080/org.apache.dubbo.samples.rest.GreetingService
```
## Expected Behavior
A REST consumer should not need to manually import Dubbo protocol just
because it uses application-level service discovery.
If the metadata service internally uses Dubbo protocol, that dependency
should be hidden by the service discovery / metadata module, or the error
should clearly explain the required import.
## Actual Behavior
The REST consumer fails at runtime because service discovery tries to call
the metadata service through `dubbo://...`, but the Dubbo protocol extension is
not registered.
## Why This Matters
This leaks an internal metadata transport detail into user code. From the
user perspective, the configured service protocol is REST, the registry is
ZooKeeper/Nacos, and the registry type is application-level service discovery.
Requiring a Dubbo protocol import is non-obvious and easy to miss.
## Suggested Fix
One of the following would improve the behavior:
1. service discovery automatically registers the protocol needed for
metadata service calls;
2. provide a documented import bundle for application-level service
discovery dependencies;
3. return a clearer error such as: `metadata service uses dubbo protocol,
please import dubbo.apache.org/dubbo-go/v3/protocol/dubbo`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]