From 4081b84766426f5b5d8db48f0e20051fbd49259b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=9B=E5=8A=AA?= Date: Wed, 17 Nov 2021 11:41:31 +0800 Subject: [PATCH] topic event request add metadata field --- .../mosn/layotto/v1/grpc/PubsubConverter.java | 1 + .../proto/runtime/v1/AppCallbackProto.java | 442 +++++++++++++++++- spec/proto/runtime/v1/appcallback.proto | 3 + 3 files changed, 424 insertions(+), 22 deletions(-) diff --git a/sdk/java-sdk/sdk/src/main/java/io/mosn/layotto/v1/grpc/PubsubConverter.java b/sdk/java-sdk/sdk/src/main/java/io/mosn/layotto/v1/grpc/PubsubConverter.java index 718589d98c..0c1785965b 100644 --- a/sdk/java-sdk/sdk/src/main/java/io/mosn/layotto/v1/grpc/PubsubConverter.java +++ b/sdk/java-sdk/sdk/src/main/java/io/mosn/layotto/v1/grpc/PubsubConverter.java @@ -98,6 +98,7 @@ public static TopicEventRequest TopicEventRequest2Domain(AppCallbackProto.TopicE result.setType(req.getType()); result.setSpecVersion(req.getSpecVersion()); result.setContentType(req.getDataContentType()); + result.setMetadata(req.getMetadataMap()); ByteString byteString = req.getData(); if (byteString == null) { result.setData(new byte[]{}); diff --git a/sdk/java-sdk/sdk/src/main/java/spec/proto/runtime/v1/AppCallbackProto.java b/sdk/java-sdk/sdk/src/main/java/spec/proto/runtime/v1/AppCallbackProto.java index ba82b8e84e..3477433cc4 100644 --- a/sdk/java-sdk/sdk/src/main/java/spec/proto/runtime/v1/AppCallbackProto.java +++ b/sdk/java-sdk/sdk/src/main/java/spec/proto/runtime/v1/AppCallbackProto.java @@ -179,6 +179,60 @@ public interface TopicEventRequestOrBuilder extends */ com.google.protobuf.ByteString getPubsubNameBytes(); + + /** + *
+     * add a map to pass some extra properties.
+     * 
+ * + * map<string, string> metadata = 10; + */ + int getMetadataCount(); + /** + *
+     * add a map to pass some extra properties.
+     * 
+ * + * map<string, string> metadata = 10; + */ + boolean containsMetadata( + java.lang.String key); + /** + * Use {@link #getMetadataMap()} instead. + */ + @java.lang.Deprecated + java.util.Map + getMetadata(); + /** + *
+     * add a map to pass some extra properties.
+     * 
+ * + * map<string, string> metadata = 10; + */ + java.util.Map + getMetadataMap(); + /** + *
+     * add a map to pass some extra properties.
+     * 
+ * + * map<string, string> metadata = 10; + */ + + java.lang.String getMetadataOrDefault( + java.lang.String key, + java.lang.String defaultValue); + /** + *
+     * add a map to pass some extra properties.
+     * 
+ * + * map<string, string> metadata = 10; + */ + + java.lang.String getMetadataOrThrow( + java.lang.String key); } /** *
@@ -228,6 +282,7 @@ private TopicEventRequest(
       if (extensionRegistry == null) {
         throw new java.lang.NullPointerException();
       }
+      int mutable_bitField0_ = 0;
       com.google.protobuf.UnknownFieldSet.Builder unknownFields =
           com.google.protobuf.UnknownFieldSet.newBuilder();
       try {
@@ -285,6 +340,19 @@ private TopicEventRequest(
               pubsubName_ = s;
               break;
             }
+            case 82: {
+              if (!((mutable_bitField0_ & 0x00000001) != 0)) {
+                metadata_ = com.google.protobuf.MapField.newMapField(
+                    MetadataDefaultEntryHolder.defaultEntry);
+                mutable_bitField0_ |= 0x00000001;
+              }
+              com.google.protobuf.MapEntry
+              metadata__ = input.readMessage(
+                  MetadataDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry);
+              metadata_.getMutableMap().put(
+                  metadata__.getKey(), metadata__.getValue());
+              break;
+            }
             default: {
               if (!parseUnknownField(
                   input, unknownFields, extensionRegistry, tag)) {
@@ -309,6 +377,18 @@ private TopicEventRequest(
       return spec.proto.runtime.v1.AppCallbackProto.internal_static_spec_proto_runtime_v1_TopicEventRequest_descriptor;
     }
 
+    @SuppressWarnings({"rawtypes"})
+    @java.lang.Override
+    protected com.google.protobuf.MapField internalGetMapField(
+        int number) {
+      switch (number) {
+        case 10:
+          return internalGetMetadata();
+        default:
+          throw new RuntimeException(
+              "Invalid map field number: " + number);
+      }
+    }
     @java.lang.Override
     protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
         internalGetFieldAccessorTable() {
@@ -666,6 +746,103 @@ public java.lang.String getPubsubName() {
       }
     }
 
+    public static final int METADATA_FIELD_NUMBER = 10;
+    private static final class MetadataDefaultEntryHolder {
+      static final com.google.protobuf.MapEntry<
+          java.lang.String, java.lang.String> defaultEntry =
+              com.google.protobuf.MapEntry
+              .newDefaultInstance(
+                  spec.proto.runtime.v1.AppCallbackProto.internal_static_spec_proto_runtime_v1_TopicEventRequest_MetadataEntry_descriptor, 
+                  com.google.protobuf.WireFormat.FieldType.STRING,
+                  "",
+                  com.google.protobuf.WireFormat.FieldType.STRING,
+                  "");
+    }
+    private com.google.protobuf.MapField<
+        java.lang.String, java.lang.String> metadata_;
+    private com.google.protobuf.MapField
+    internalGetMetadata() {
+      if (metadata_ == null) {
+        return com.google.protobuf.MapField.emptyMapField(
+            MetadataDefaultEntryHolder.defaultEntry);
+      }
+      return metadata_;
+    }
+
+    public int getMetadataCount() {
+      return internalGetMetadata().getMap().size();
+    }
+    /**
+     * 
+     * add a map to pass some extra properties.
+     * 
+ * + * map<string, string> metadata = 10; + */ + + @java.lang.Override + public boolean containsMetadata( + java.lang.String key) { + if (key == null) { throw new java.lang.NullPointerException(); } + return internalGetMetadata().getMap().containsKey(key); + } + /** + * Use {@link #getMetadataMap()} instead. + */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getMetadata() { + return getMetadataMap(); + } + /** + *
+     * add a map to pass some extra properties.
+     * 
+ * + * map<string, string> metadata = 10; + */ + @java.lang.Override + + public java.util.Map getMetadataMap() { + return internalGetMetadata().getMap(); + } + /** + *
+     * add a map to pass some extra properties.
+     * 
+ * + * map<string, string> metadata = 10; + */ + @java.lang.Override + + public java.lang.String getMetadataOrDefault( + java.lang.String key, + java.lang.String defaultValue) { + if (key == null) { throw new java.lang.NullPointerException(); } + java.util.Map map = + internalGetMetadata().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + *
+     * add a map to pass some extra properties.
+     * 
+ * + * map<string, string> metadata = 10; + */ + @java.lang.Override + + public java.lang.String getMetadataOrThrow( + java.lang.String key) { + if (key == null) { throw new java.lang.NullPointerException(); } + java.util.Map map = + internalGetMetadata().getMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return map.get(key); + } + private byte memoizedIsInitialized = -1; @java.lang.Override public final boolean isInitialized() { @@ -704,6 +881,12 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (!getPubsubNameBytes().isEmpty()) { com.google.protobuf.GeneratedMessageV3.writeString(output, 8, pubsubName_); } + com.google.protobuf.GeneratedMessageV3 + .serializeStringMapTo( + output, + internalGetMetadata(), + MetadataDefaultEntryHolder.defaultEntry, + 10); unknownFields.writeTo(output); } @@ -738,6 +921,16 @@ public int getSerializedSize() { if (!getPubsubNameBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(8, pubsubName_); } + for (java.util.Map.Entry entry + : internalGetMetadata().getMap().entrySet()) { + com.google.protobuf.MapEntry + metadata__ = MetadataDefaultEntryHolder.defaultEntry.newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build(); + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(10, metadata__); + } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; @@ -769,6 +962,8 @@ public boolean equals(final java.lang.Object obj) { .equals(other.getTopic())) return false; if (!getPubsubName() .equals(other.getPubsubName())) return false; + if (!internalGetMetadata().equals( + other.internalGetMetadata())) return false; if (!unknownFields.equals(other.unknownFields)) return false; return true; } @@ -796,6 +991,10 @@ public int hashCode() { hash = (53 * hash) + getTopic().hashCode(); hash = (37 * hash) + PUBSUB_NAME_FIELD_NUMBER; hash = (53 * hash) + getPubsubName().hashCode(); + if (!internalGetMetadata().getMap().isEmpty()) { + hash = (37 * hash) + METADATA_FIELD_NUMBER; + hash = (53 * hash) + internalGetMetadata().hashCode(); + } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; @@ -908,6 +1107,28 @@ public static final class Builder extends return spec.proto.runtime.v1.AppCallbackProto.internal_static_spec_proto_runtime_v1_TopicEventRequest_descriptor; } + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapField internalGetMapField( + int number) { + switch (number) { + case 10: + return internalGetMetadata(); + default: + throw new RuntimeException( + "Invalid map field number: " + number); + } + } + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapField internalGetMutableMapField( + int number) { + switch (number) { + case 10: + return internalGetMutableMetadata(); + default: + throw new RuntimeException( + "Invalid map field number: " + number); + } + } @java.lang.Override protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { @@ -950,6 +1171,7 @@ public Builder clear() { pubsubName_ = ""; + internalGetMutableMetadata().clear(); return this; } @@ -976,6 +1198,7 @@ public spec.proto.runtime.v1.AppCallbackProto.TopicEventRequest build() { @java.lang.Override public spec.proto.runtime.v1.AppCallbackProto.TopicEventRequest buildPartial() { spec.proto.runtime.v1.AppCallbackProto.TopicEventRequest result = new spec.proto.runtime.v1.AppCallbackProto.TopicEventRequest(this); + int from_bitField0_ = bitField0_; result.id_ = id_; result.source_ = source_; result.type_ = type_; @@ -984,6 +1207,8 @@ public spec.proto.runtime.v1.AppCallbackProto.TopicEventRequest buildPartial() { result.data_ = data_; result.topic_ = topic_; result.pubsubName_ = pubsubName_; + result.metadata_ = internalGetMetadata(); + result.metadata_.makeImmutable(); onBuilt(); return result; } @@ -1063,6 +1288,8 @@ public Builder mergeFrom(spec.proto.runtime.v1.AppCallbackProto.TopicEventReques pubsubName_ = other.pubsubName_; onChanged(); } + internalGetMutableMetadata().mergeFrom( + other.internalGetMetadata()); this.mergeUnknownFields(other.unknownFields); onChanged(); return this; @@ -1091,6 +1318,7 @@ public Builder mergeFrom( } return this; } + private int bitField0_; private java.lang.Object id_ = ""; /** @@ -1839,6 +2067,162 @@ public Builder setPubsubNameBytes( onChanged(); return this; } + + private com.google.protobuf.MapField< + java.lang.String, java.lang.String> metadata_; + private com.google.protobuf.MapField + internalGetMetadata() { + if (metadata_ == null) { + return com.google.protobuf.MapField.emptyMapField( + MetadataDefaultEntryHolder.defaultEntry); + } + return metadata_; + } + private com.google.protobuf.MapField + internalGetMutableMetadata() { + onChanged();; + if (metadata_ == null) { + metadata_ = com.google.protobuf.MapField.newMapField( + MetadataDefaultEntryHolder.defaultEntry); + } + if (!metadata_.isMutable()) { + metadata_ = metadata_.copy(); + } + return metadata_; + } + + public int getMetadataCount() { + return internalGetMetadata().getMap().size(); + } + /** + *
+       * add a map to pass some extra properties.
+       * 
+ * + * map<string, string> metadata = 10; + */ + + @java.lang.Override + public boolean containsMetadata( + java.lang.String key) { + if (key == null) { throw new java.lang.NullPointerException(); } + return internalGetMetadata().getMap().containsKey(key); + } + /** + * Use {@link #getMetadataMap()} instead. + */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getMetadata() { + return getMetadataMap(); + } + /** + *
+       * add a map to pass some extra properties.
+       * 
+ * + * map<string, string> metadata = 10; + */ + @java.lang.Override + + public java.util.Map getMetadataMap() { + return internalGetMetadata().getMap(); + } + /** + *
+       * add a map to pass some extra properties.
+       * 
+ * + * map<string, string> metadata = 10; + */ + @java.lang.Override + + public java.lang.String getMetadataOrDefault( + java.lang.String key, + java.lang.String defaultValue) { + if (key == null) { throw new java.lang.NullPointerException(); } + java.util.Map map = + internalGetMetadata().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + *
+       * add a map to pass some extra properties.
+       * 
+ * + * map<string, string> metadata = 10; + */ + @java.lang.Override + + public java.lang.String getMetadataOrThrow( + java.lang.String key) { + if (key == null) { throw new java.lang.NullPointerException(); } + java.util.Map map = + internalGetMetadata().getMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return map.get(key); + } + + public Builder clearMetadata() { + internalGetMutableMetadata().getMutableMap() + .clear(); + return this; + } + /** + *
+       * add a map to pass some extra properties.
+       * 
+ * + * map<string, string> metadata = 10; + */ + + public Builder removeMetadata( + java.lang.String key) { + if (key == null) { throw new java.lang.NullPointerException(); } + internalGetMutableMetadata().getMutableMap() + .remove(key); + return this; + } + /** + * Use alternate mutation accessors instead. + */ + @java.lang.Deprecated + public java.util.Map + getMutableMetadata() { + return internalGetMutableMetadata().getMutableMap(); + } + /** + *
+       * add a map to pass some extra properties.
+       * 
+ * + * map<string, string> metadata = 10; + */ + public Builder putMetadata( + java.lang.String key, + java.lang.String value) { + if (key == null) { throw new java.lang.NullPointerException(); } + if (value == null) { throw new java.lang.NullPointerException(); } + internalGetMutableMetadata().getMutableMap() + .put(key, value); + return this; + } + /** + *
+       * add a map to pass some extra properties.
+       * 
+ * + * map<string, string> metadata = 10; + */ + + public Builder putAllMetadata( + java.util.Map values) { + internalGetMutableMetadata().getMutableMap() + .putAll(values); + return this; + } @java.lang.Override public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { @@ -4706,6 +5090,11 @@ public spec.proto.runtime.v1.AppCallbackProto.TopicSubscription getDefaultInstan private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_spec_proto_runtime_v1_TopicEventRequest_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_spec_proto_runtime_v1_TopicEventRequest_MetadataEntry_descriptor; + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_spec_proto_runtime_v1_TopicEventRequest_MetadataEntry_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_spec_proto_runtime_v1_TopicEventResponse_descriptor; private static final @@ -4737,30 +5126,33 @@ public spec.proto.runtime.v1.AppCallbackProto.TopicSubscription getDefaultInstan java.lang.String[] descriptorData = { "\n\"proto/runtime/v1/appcallback.proto\022\025sp" + "ec.proto.runtime.v1\032\033google/protobuf/emp" + - "ty.proto\"\240\001\n\021TopicEventRequest\022\n\n\002id\030\001 \001" + + "ty.proto\"\233\002\n\021TopicEventRequest\022\n\n\002id\030\001 \001" + "(\t\022\016\n\006source\030\002 \001(\t\022\014\n\004type\030\003 \001(\t\022\024\n\014spec" + "_version\030\004 \001(\t\022\031\n\021data_content_type\030\005 \001(" + "\t\022\014\n\004data\030\007 \001(\014\022\r\n\005topic\030\006 \001(\t\022\023\n\013pubsub" + - "_name\030\010 \001(\t\"\246\001\n\022TopicEventResponse\022R\n\006st" + - "atus\030\001 \001(\0162B.spec.proto.runtime.v1.Topic" + - "EventResponse.TopicEventResponseStatus\"<" + - "\n\030TopicEventResponseStatus\022\013\n\007SUCCESS\020\000\022" + - "\t\n\005RETRY\020\001\022\010\n\004DROP\020\002\"a\n\036ListTopicSubscri" + - "ptionsResponse\022?\n\rsubscriptions\030\001 \003(\0132(." + - "spec.proto.runtime.v1.TopicSubscription\"" + - "\262\001\n\021TopicSubscription\022\023\n\013pubsub_name\030\001 \001" + - "(\t\022\r\n\005topic\030\002 \001(\t\022H\n\010metadata\030\003 \003(\01326.sp" + - "ec.proto.runtime.v1.TopicSubscription.Me" + - "tadataEntry\032/\n\rMetadataEntry\022\013\n\003key\030\001 \001(" + - "\t\022\r\n\005value\030\002 \001(\t:\0028\0012\337\001\n\013AppCallback\022i\n\026" + - "ListTopicSubscriptions\022\026.google.protobuf" + - ".Empty\0325.spec.proto.runtime.v1.ListTopic" + - "SubscriptionsResponse\"\000\022e\n\014OnTopicEvent\022" + - "(.spec.proto.runtime.v1.TopicEventReques" + - "t\032).spec.proto.runtime.v1.TopicEventResp" + - "onse\"\000BX\n\025spec.proto.runtime.v1B\020AppCall" + - "backProtoZ-mosn.io/layotto/spec/proto/ru" + - "ntime/v1;runtimeb\006proto3" + "_name\030\010 \001(\t\022H\n\010metadata\030\n \003(\01326.spec.pro" + + "to.runtime.v1.TopicEventRequest.Metadata" + + "Entry\032/\n\rMetadataEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005v" + + "alue\030\002 \001(\t:\0028\001\"\246\001\n\022TopicEventResponse\022R\n" + + "\006status\030\001 \001(\0162B.spec.proto.runtime.v1.To" + + "picEventResponse.TopicEventResponseStatu" + + "s\"<\n\030TopicEventResponseStatus\022\013\n\007SUCCESS" + + "\020\000\022\t\n\005RETRY\020\001\022\010\n\004DROP\020\002\"a\n\036ListTopicSubs" + + "criptionsResponse\022?\n\rsubscriptions\030\001 \003(\013" + + "2(.spec.proto.runtime.v1.TopicSubscripti" + + "on\"\262\001\n\021TopicSubscription\022\023\n\013pubsub_name\030" + + "\001 \001(\t\022\r\n\005topic\030\002 \001(\t\022H\n\010metadata\030\003 \003(\01326" + + ".spec.proto.runtime.v1.TopicSubscription" + + ".MetadataEntry\032/\n\rMetadataEntry\022\013\n\003key\030\001" + + " \001(\t\022\r\n\005value\030\002 \001(\t:\0028\0012\337\001\n\013AppCallback\022" + + "i\n\026ListTopicSubscriptions\022\026.google.proto" + + "buf.Empty\0325.spec.proto.runtime.v1.ListTo" + + "picSubscriptionsResponse\"\000\022e\n\014OnTopicEve" + + "nt\022(.spec.proto.runtime.v1.TopicEventReq" + + "uest\032).spec.proto.runtime.v1.TopicEventR" + + "esponse\"\000BX\n\025spec.proto.runtime.v1B\020AppC" + + "allbackProtoZ-mosn.io/layotto/spec/proto" + + "/runtime/v1;runtimeb\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, @@ -4772,7 +5164,13 @@ public spec.proto.runtime.v1.AppCallbackProto.TopicSubscription getDefaultInstan internal_static_spec_proto_runtime_v1_TopicEventRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_spec_proto_runtime_v1_TopicEventRequest_descriptor, - new java.lang.String[] { "Id", "Source", "Type", "SpecVersion", "DataContentType", "Data", "Topic", "PubsubName", }); + new java.lang.String[] { "Id", "Source", "Type", "SpecVersion", "DataContentType", "Data", "Topic", "PubsubName", "Metadata", }); + internal_static_spec_proto_runtime_v1_TopicEventRequest_MetadataEntry_descriptor = + internal_static_spec_proto_runtime_v1_TopicEventRequest_descriptor.getNestedTypes().get(0); + internal_static_spec_proto_runtime_v1_TopicEventRequest_MetadataEntry_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_spec_proto_runtime_v1_TopicEventRequest_MetadataEntry_descriptor, + new java.lang.String[] { "Key", "Value", }); internal_static_spec_proto_runtime_v1_TopicEventResponse_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_spec_proto_runtime_v1_TopicEventResponse_fieldAccessorTable = new diff --git a/spec/proto/runtime/v1/appcallback.proto b/spec/proto/runtime/v1/appcallback.proto index e66f5b438e..1f21d763bb 100644 --- a/spec/proto/runtime/v1/appcallback.proto +++ b/spec/proto/runtime/v1/appcallback.proto @@ -56,6 +56,9 @@ message TopicEventRequest { // The name of the pubsub the publisher sent to. string pubsub_name = 8; + + // add a map to pass some extra properties. + map metadata = 10; } // TopicEventResponse is response from app on published message