Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/alexandrevicenzi/go-sse"
"github.com/gobuffalo/packr"
"gopkg.in/yaml.v2"
"html/template"
"io/ioutil"
"log"
Expand All @@ -16,6 +13,10 @@ import (
"strings"
"sync"

"github.com/alexandrevicenzi/go-sse"
"github.com/gobuffalo/packr"
"gopkg.in/yaml.v2"

"cloud.google.com/go/pubsub"
)

Expand Down Expand Up @@ -192,7 +193,7 @@ func pullMessages(ctx context.Context, subscription *pubsub.Subscription, topic
cctx, _ := context.WithCancel(ctx)
err := subscription.Receive(cctx, func(ctx context.Context, msg *pubsub.Message) {
msg.Ack()
log.Printf("Project [%s], topic [%s], subscription [%s], got message: %q\n", project, topic.ID(), subscription.ID(), string(msg.Data))
log.Printf("Project [%s], topic [%s], subscription [%s], got message: %q, with attributes: %v\n", project, topic.ID(), subscription.ID(), string(msg.Data), msg.Attributes)

topicID := fmt.Sprintf("%s/%s", project, topic.ID())
messages[topicID] = append([]pubsub.Message{*msg}, messages[topicID]...)
Expand Down
21 changes: 16 additions & 5 deletions static/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,22 @@ <h4>Topics</h4>
<li class="collection-header"><h5>{{ "{{ topic }}" }}</h5></li>
<li v-for="message in messages" class="collection-item" :key="message.ID">
<span style="font-size: 10px; color: #333333;">{{ "{{ message.PublishTime }}" }} (ID {{ "{{ message.ID }}" }}):</span>
<pre>
<code class="language-json">
{{ "{{ atob(message.Data) }}" }}
</code>
</pre>
<div v-if="message.Data">
<span style="font-size: 8px; color: #333333;">message.Data:</span>
<pre>
<code class="language-json">
{{ "{{ atob(message.Data) }}" }}
</code>
</pre>
</div>
<div v-if="message.Attributes">
<span style="font-size: 8px; color: #333333;">message.Attributes:</span>
<pre>
<code class="language-json">
{{ "{{ message.Attributes }}" }}
</code>
</pre>
</div>
</li>
</ul>
<p v-if="Object.keys(topics).length == 0">No messages yet 📭</p>
Expand Down