You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "merlimat (via GitHub)" <gi...@apache.org> on 2024/03/27 17:50:40 UTC

Re: [PR] Enable accessing Message in TableView [pulsar-client-go]

merlimat commented on code in PR #1174:
URL: https://github.com/apache/pulsar-client-go/pull/1174#discussion_r1541581408


##########
pulsar/table_view_impl.go:
##########
@@ -186,10 +203,23 @@ func (tv *TableViewImpl) Get(key string) interface{} {
 func (tv *TableViewImpl) Entries() map[string]interface{} {
 	tv.dataMu.Lock()
 	defer tv.dataMu.Unlock()
+
 	data := make(map[string]interface{}, len(tv.data))
-	for k, v := range tv.data {
+	for k, msg := range tv.data {
+		v, err := tv.schemaValueFromMessage(msg)
+		if err != nil {
+			tv.logger.Errorf("getting value for message, %w; msg is %v", len(tv.listeners), err, msg)
+			continue
+		}
 		data[k] = v
 	}
+
+	return data
+}
+
+func (tv *TableViewImpl) Messages() map[string]Message {
+	tv.dataMu.Lock()
+	defer tv.dataMu.Unlock()

Review Comment:
   This is returning the same underlying map, allowing for race-conditions and modifications from the application. 
   
   Note: the existing code is also wrong because it was returning `tv.data` instead of `data`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org