-
Notifications
You must be signed in to change notification settings - Fork 801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SCB-926] support invoking 3rd party service #915
Conversation
|
||
/** | ||
* @see #registryMicroserviceMapping(String, String, Class, List) | ||
* @param endpoints the endpoints of 3rd party service. Each of endpoints will be treated as a separated instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add example for endpoint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the example is added in the comment of method registerMicroserviceMappingByEndpoints
.computeIfAbsent(microserviceName, | ||
svcName -> new StaticMicroserviceVersions(this.appManager, app, microserviceName, schemaIntfCls)); | ||
|
||
microserviceVersions.addInstances(version, instances); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addInstances should put inside computeIfAbsent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addInstances
is put inside computeIfAbsent
. Currently only initial instance method is provided. Users cannot re-set instance info of a 3rd party service.
Assert.assertEquals("abc", stringBodyResponse.getBody()); | ||
} | ||
|
||
@Path("/rest/it-producer/v1/dataTypeJaxrs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for different deploy mode, target microservice name is different.
so "it-producer" can not hard code
based on zhengyangyong's PR, if that one merged first, then this one will failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked zhengyangyong's commits and test it by rebasing those commits into my branch. There is no problem with the producer's service name because other deploy mode will not trigger this test.
The only problem is the initialization method of GateRestTemplate
is changed. And I've changed to use new initialization method in new commit.
@@ -40,6 +41,8 @@ public static CseContext getInstance() { | |||
|
|||
private ConsumerSchemaFactory consumerSchemaFactory; | |||
|
|||
private StaticSchemaFactory staticSchemaFactory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CseContext will de Deprecated, use ScbEngine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -103,4 +109,12 @@ protected SwaggerGenerator generateSwagger(CONTEXT context) { | |||
|
|||
return generator; | |||
} | |||
|
|||
protected String getSwaggerContent(Swagger swagger) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just use SwaggerUtils?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
MicroserviceInstance instance = new MicroserviceInstance(); | ||
instance.setEndpoints(Collections.singletonList(endpoint)); | ||
RegistryUtils.getServiceRegistry() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two scenarios need to consider:
- consumers register producers endpoints and schemas
- consumers register only schemas, this is quite common in mesher mode which the service is already registered to service center but schemas are not, and used very widely
Can we provide scenario 2 support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've asked wujimin's opinion and maybe we can have a new discussion on the scenario that there are microservices registered in sc with only instance info but no schema.
This issue is planned to provide the basic ability to invoke 3rd party service.
f09fd7e
to
9c233d6
Compare
@@ -45,6 +48,8 @@ | |||
@Inject | |||
protected CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext; | |||
|
|||
private ObjectWriter writer = Yaml.pretty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, has been fixed.
private MicroserviceMeta microserviceMeta; | ||
MicroserviceMeta microserviceMeta; | ||
|
||
MicroserviceVersionMeta(Microservice microservice) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
microserviceMeta is not initialized, and getMicroserviceMeta may return null and cause NPE.
From the following code, I think it's better to define the method protected that should be overrided by sub class.
Or remove this constructor and define microserviceMeta to be protected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
microserviceMeta
in MicroserviceVersionMeta
is initialized in constructors and has package access modifier which ensures that the classes out of its package can only get access to it by getter method. So I think NPE can be avoid since users can only get microserviceMeta
after it is initialized.
* @param instances the instances of this 3rd party service. Users only need to specify the endpoint information, other | ||
* necessary information will be generate and set in the implementation of this method. | ||
*/ | ||
void registerMicroserviceMapping(String microserviceName, String version, Class<?> schemaIntfCls, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to put schemaIntfCls as last parameter, since we can extend it to schemaIntfCls... to support several schemas. I think this is quite normal in many scenarios like register a gateway service as a third party service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we should consider multiple schemas in the next step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
9c233d6
to
49bd8bf
Compare
…e, move StaticSchemaFactory into SCBEngine
74f1fbe
to
be9f265
Compare
Follow this checklist to help us incorporate your contribution quickly and easily:
[SCB-XXX] Fixes bug in ApproximateQuantiles
, where you replaceSCB-XXX
with the appropriate JIRA issue.mvn clean install
to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.Support invoking 3rd party service just like invoking ServiceComb microservice registered in service-center.