QGrpcHttp2Channel Class

Die Klasse QGrpcHttp2Channel bietet eine HTTP/2-Transportschicht für gRPC Kommunikation. Mehr...

Header: #include <QGrpcHttp2Channel>
CMake: find_package(Qt6 REQUIRED COMPONENTS Grpc)
target_link_libraries(mytarget PRIVATE Qt6::Grpc)
Seit: Qt 6.5
In QML: GrpcHttp2Channel
Vererbt: QAbstractGrpcChannel

Öffentliche Funktionen

QGrpcHttp2Channel(const QUrl &hostUri)
QGrpcHttp2Channel(const QUrl &hostUri, const QGrpcChannelOptions &options)
virtual ~QGrpcHttp2Channel() override
QUrl hostUri() const

Detaillierte Beschreibung

Die Klasse QGrpcHttp2Channel implementiert QAbstractGrpcChannel und ermöglicht gRPC Kommunikation über HTTP/2 Framing.

HTTP/2 bietet mehrere Vorteile gegenüber seinem Vorgänger HTTP/1.1, wodurch sich QGrpcHttp2Channel gut für Hochleistungs-Echtzeitanwendungen eignet, die eine effiziente Kommunikation erfordern, ohne dass die Sicherheit oder Zuverlässigkeit durch die Verwendung von Multiplex-TCP-Verbindungen beeinträchtigt wird.

Der Kanal kann mit SSL-Unterstützung, einer benutzerdefinierten serializationFormat oder anderen Optionen angepasst werden, indem er mit einer QGrpcChannelOptions konstruiert wird, die die erforderlichen Anpassungen enthält.

Inhalts-Typ

Der Inhaltstyp in gRPC über HTTP/2 bestimmt das Format der Nachrichtenserialisierung. Er muss mit application/grpc beginnen und kann ein Suffix enthalten. Das Format folgt diesem Schema:

"content-type": "application/grpc" [("+proto" / "+json" / {custom})]

Zum Beispiel:

  • application/grpc+proto gibt die Protobuf-Kodierung an.
  • application/grpc+json gibt die JSON-Kodierung an.

Das Serialisierungsformat kann entweder durch Angabe von content-type innerhalb der Metadaten oder durch direkte Angabe von serializationFormat konfiguriert werden. Standardmäßig wird der Inhaltstyp application/grpc verwendet.

So konfigurieren Sie QGrpcHttp2Channel mit dem JSON-Serialisierungsformat unter Verwendung von content-type metadata:

auto jsonChannel = std::make_shared<QGrpcHttp2Channel>(
    QUrl("http://localhost:50051"_L1),
    QGrpcChannelOptions().setMetadata({
        { "content-type"_ba, "application/grpc+json"_ba },
    })
);

Für einen benutzerdefinierten Serializer und content-type können Sie das Serialisierungsformat direkt festlegen:

class DummySerializer : public QAbstractProtobufSerializer
{
    ...
};
QGrpcSerializationFormat dummyFormat("dummy", std::make_shared<DummySerializer>());
auto dummyChannel = std::make_shared<QGrpcHttp2Channel>(
    QUrl("http://localhost:50051"_L1),
    QGrpcChannelOptions().setSerializationFormat(dummyFormat)
);

Dies verwendet DummySerializer für die Kodierung und Dekodierung von Nachrichten mit dem Suffix dummy. Für den HTTP/2-Transport ergibt sich daraus der Inhaltstyp application/grpc+dummy.

Hinweis: Benutzerdefinierte Serialisierer erfordern Serverunterstützung für das angegebene Format.

Siehe auch QAbstractGrpcChannel, QGrpcChannelOptions, und QGrpcSerializationFormat.

Dokumentation der Mitgliedsfunktionen

[explicit] QGrpcHttp2Channel::QGrpcHttp2Channel(const QUrl &hostUri)

Konstruiert QGrpcHttp2Channel mit hostUri.

[explicit] QGrpcHttp2Channel::QGrpcHttp2Channel(const QUrl &hostUri, const QGrpcChannelOptions &options)

Konstruiert QGrpcHttp2Channel mit hostUri und options.

[override virtual noexcept] QGrpcHttp2Channel::~QGrpcHttp2Channel()

Zerstört das Objekt QGrpcHttp2Channel.

QUrl QGrpcHttp2Channel::hostUri() const

Gibt den Host-URI für diesen Kanal zurück.

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.