Multple same named files from different sources

64 views
Skip to first unread message

Sergey Shcherbin

unread,
Jul 26, 2022, 7:14:59 AM7/26/22
to Protocol Buffers
Hello,

Set up:

2 separate services having their own protobuf files.
Service1 :
service.proto
queries.proto

Service2:
service.proto (different from service1)
queries.proto (different from service1)
filters.proto

And a mediator service (gateway) which needs to query both services for data through grpc calls.

Service1 and Service2 have different package names in proto files and different namespaces configured in options (php plugin)

Problem:
Once I try to compile them and include in project everything will be fine till i will try to
create objects from same named proto files (eventho namespaces will be different)
example:

<?php
declare(strict_types = 1);
require __DIR__ . '/vendor/autoload.php';
$q1 = new \Service1\SearchQuery();
$q2 = new \Service2\FilteredQuery(); <- problem will occur here



I've traced it to the way pool is set up in generated files:
\Google\Protobuf\Internal\DescriptorPool::getGeneratedPool()
its one for all namespaces.

Obvious solution is to rename proto files to be named separately in both services, but that kind of breaks service independence

Question:
Is there a proper way of handling this situation?
Maybe I am misusing protobuf concept?

Deanna Garcia

unread,
Aug 1, 2022, 1:32:52 PM8/1/22
to Protocol Buffers
A few questions:
  • What language is this for? Only PHP protos?
  • Is there a reason for needing the two distinct proto files? Can you reuse one of them for the other service?
  • Are you setting the `php_class_prefix` option in your `.proto` file? If not, I think this might be a way to implement your intended behavior.

Sergey Shcherbin

unread,
Aug 2, 2022, 4:36:19 AM8/2/22
to Deanna Garcia, Protocol Buffers
Hello Deanna,

Thank you for your reply.

What language is this for? Only PHP protos? -> Yes, It's only for the PHP language

Is there a reason for needing the two distinct proto files? Can you reuse one of them for the other service? -> Main service is a mediator service, it needs to call both services in order to perform a task. Included services have their own protobuf files describing them

Are you setting the `php_class_prefix` option in your `.proto` file? If not, I think this might be a way to implement your intended behavior. ->
Protofile from the first service sets php_metadata_namespace + php_namespace resulting in namespace \Service\Service1Namespace and the second service has no such options and a resulting namespace is \Service
Problem is not within PHP loading mechanics since it will be able to load both of those services. Problem will be in autogenerated classes using same pool and having same protofile name (queries.proto)

--
You received this message because you are subscribed to a topic in the Google Groups "Protocol Buffers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/protobuf/eC-9x7av8wY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/6f136f19-3a41-4fb6-8cf8-00f855d2402dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages