【发布时间】:2019-05-21 08:55:52
【问题描述】:
这里是新手程序员的问题。我有一个 pubsub 的发布者代码,我在其中从数据库查询并将结果存储在 C# 中的 LIST 中。现在我需要将该 LIST 作为消息传递给 pubsub 主题。我怎样才能做到这一点?
var egv_data = do_cgmdata_query(conn); //query method
if (egv_data != null)
{
while (egv_data.Read())
{
Participant_List_Data.Add(new Participant_Data()
{
fitbit_id = (string)egv_data[0],
sf_candidate_id = (string)egv_data[1],
egv = (string)egv_data[2],
egv_datetimelocal = (string)egv_data[3]
});
}
egv_data.Close();
//publish a message to the topic
foreach (Participant_Data aList in Participant_List_Data)
{
PubsubMessage message = new PubsubMessage
{
Data = aList /*need to pass this correctly to pubsub topic, aList.fitbit_id, aList.egv...etc*/
Attributes = {
{"version","1.0"}
}
};
//publish the message to topic
pub.Publish(topicName, new[] { message });
}
}
【问题讨论】:
-
PubsubMessage.Data是Participant_Data类型的对象吗?
标签: c# publish-subscribe