// Listens for connections and starts a proton.Engine for each one. func (b *broker) run() error { listener, err := net.Listen("tcp", *addr) if err != nil { return err } defer listener.Close() fmt.Printf("Listening on %s\n", listener.Addr()) for { conn, err := listener.Accept() if err != nil { util.Debugf("Accept error: %v", err) continue } adapter := proton.NewMessagingAdapter(newHandler(&b.queues)) // We want to accept messages when they are enqueued, not just when they // are received, so we turn off auto-accept and prefetch by the adapter. adapter.Prefetch = 0 adapter.AutoAccept = false engine, err := proton.NewEngine(conn, adapter) if err != nil { util.Debugf("Connection error: %v", err) continue } engine.Server() // Enable server-side protocol negotiation. util.Debugf("Accepted connection %s", engine) go func() { // Start goroutine to run the engine event loop engine.Run() util.Debugf("Closed %s", engine) }() } }
func newHandler(c *connection) *handler { h := &handler{ connection: c, links: make(map[proton.Link]Endpoint), sentMessages: make(map[proton.Delivery]sentMessage), sessions: make(map[proton.Session]*session), } h.delegator = proton.NewMessagingAdapter(h) // Disable auto features of MessagingAdapter, we do these ourselves. h.delegator.Prefetch = 0 h.delegator.AutoAccept = false h.delegator.AutoSettle = false h.delegator.AutoOpen = false return h }