This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Master issue: #2
- Loading branch information
Showing
8 changed files
with
467 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package pulsar | ||
|
||
import "github.com/golang/protobuf/proto" | ||
|
||
type Message struct { | ||
messageID MessageID | ||
payload []byte | ||
topic string | ||
properties map[string]string | ||
} | ||
|
||
func NewMessage(topic string, id MessageID, payload []byte, properties map[string]string) *Message { | ||
return &Message{ | ||
messageID: id, | ||
payload: payload, | ||
topic: topic, | ||
properties: properties, | ||
} | ||
} | ||
|
||
func (m *Message) GetMessageID() MessageID { | ||
return m.messageID | ||
} | ||
|
||
func (m *Message) GetProperties() map[string]string { | ||
return m.properties | ||
} | ||
|
||
func (m *Message) GetPayload() []byte { | ||
return m.payload | ||
} | ||
|
||
// nolint | ||
type SingleMessageMetadata struct { | ||
Properties []*KeyValue `protobuf:"bytes,1,rep,name=properties" json:"properties,omitempty"` | ||
PartitionKey *string `protobuf:"bytes,2,opt,name=partition_key,json=partitionKey" json:"partition_key,omitempty"` | ||
PayloadSize *int32 `protobuf:"varint,3,req,name=payload_size,json=payloadSize" json:"payload_size,omitempty"` | ||
CompactedOut *bool `protobuf:"varint,4,opt,name=compacted_out,json=compactedOut,def=0" json:"compacted_out,omitempty"` | ||
// the timestamp that this event occurs. it is typically set by applications. | ||
// if this field is omitted, `publish_time` can be used for the purpose of `event_time`. | ||
EventTime *uint64 `protobuf:"varint,5,opt,name=event_time,json=eventTime,def=0" json:"event_time,omitempty"` | ||
PartitionKeyB64Encoded *bool `protobuf:"varint,6,opt,name=partition_key_b64_encoded,json=partitionKeyB64Encoded,def=0" json:"partition_key_b64_encoded,omitempty"` | ||
// Specific a key to overwrite the message key which used for ordering dispatch in Key_Shared mode. | ||
OrderingKey []byte `protobuf:"bytes,7,opt,name=ordering_key,json=orderingKey" json:"ordering_key,omitempty"` | ||
XXX_NoUnkeyedLiteral struct{} `json:"-"` | ||
XXX_unrecognized []byte `json:"-"` | ||
XXX_sizecache int32 `json:"-"` | ||
} | ||
|
||
func (m *SingleMessageMetadata) Reset() { *m = SingleMessageMetadata{} } | ||
func (m *SingleMessageMetadata) String() string { return proto.CompactTextString(m) } | ||
func (*SingleMessageMetadata) ProtoMessage() {} | ||
func (m *SingleMessageMetadata) GetPayloadSize() int32 { | ||
if m != nil && m.PayloadSize != nil { | ||
return *m.PayloadSize | ||
} | ||
return 0 | ||
} | ||
|
||
// nolint | ||
type KeyValue struct { | ||
Key *string `protobuf:"bytes,1,req,name=key" json:"key,omitempty"` | ||
Value *string `protobuf:"bytes,2,req,name=value" json:"value,omitempty"` | ||
XXX_NoUnkeyedLiteral struct{} `json:"-"` | ||
XXX_unrecognized []byte `json:"-"` | ||
XXX_sizecache int32 `json:"-"` | ||
} | ||
|
||
func (m *KeyValue) Reset() { *m = KeyValue{} } | ||
func (m *KeyValue) String() string { return proto.CompactTextString(m) } | ||
func (*KeyValue) ProtoMessage() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package pulsar | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseMessageId(t *testing.T) { | ||
id, err := ParseMessageID("1:1") | ||
assert.Nil(t, err) | ||
assert.Equal(t, MessageID{LedgerID: 1, EntryID: 1, PartitionedIndex: -1, BatchIndex: -1}, *id) | ||
|
||
id, err = ParseMessageID("1:2:3") | ||
assert.Nil(t, err) | ||
assert.Equal(t, MessageID{LedgerID: 1, EntryID: 2, PartitionedIndex: 3, BatchIndex: -1}, *id) | ||
|
||
id, err = ParseMessageID("1:2:3:4") | ||
assert.Nil(t, err) | ||
assert.Equal(t, MessageID{LedgerID: 1, EntryID: 2, PartitionedIndex: 3, BatchIndex: 4}, *id) | ||
} | ||
|
||
func TestParseMessageIdErrors(t *testing.T) { | ||
id, err := ParseMessageID("1;1") | ||
assert.Nil(t, id) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "invalid message id string. 1;1", err.Error()) | ||
|
||
id, err = ParseMessageID("a:1") | ||
assert.Nil(t, id) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "invalid ledger id. a:1", err.Error()) | ||
|
||
id, err = ParseMessageID("1:a") | ||
assert.Nil(t, id) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "invalid entry id. 1:a", err.Error()) | ||
|
||
id, err = ParseMessageID("1:2:a") | ||
assert.Nil(t, id) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "invalid partition index. 1:2:a", err.Error()) | ||
|
||
id, err = ParseMessageID("1:2:3:a") | ||
assert.Nil(t, id) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "invalid batch index. 1:2:3:a", err.Error()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.