<commit_before>// Copyright © 2016 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package amqp

import (
	"fmt"
	"time"

	AMQP "github.com/streadway/amqp"
)

// Client connects to an AMQP server
type Client interface {
	Connect() error
	Disconnect()
	IsConnected() bool
	NewPublisher(exchange string) Publisher
}

// DefaultClient is the default AMQP client for The Things Network
type DefaultClient struct {
	url  string
	ctx  Logger
	conn *AMQP.Connection
}

var (
	// ConnectRetries says how many times the client should retry a failed connection
	ConnectRetries = 10
	// ConnectRetryDelay says how long the client should wait between retries
	ConnectRetryDelay = time.Second
)

// NewClient creates a new DefaultClient
func NewClient(ctx Logger, username, password, host string) Client {
	if ctx == nil {
		ctx = &noopLogger{}
	}
	credentials := "guest"
	if username != "" {
		if password != "" {
			credentials = fmt.Sprintf("%s:%s", username, password)
		} else {
			credentials = username
		}
	}
	return &DefaultClient{
		ctx: ctx,
		url: fmt.Sprintf("amqp://%s@%s", credentials, host),
	}
}

// Connect to the AMQP server. It will retry for ConnectRetries times with a delay of ConnectRetryDelay between retries
func (c *DefaultClient) Connect() error {<commit_msg>Default AMQP guest password<commit_after>// Copyright © 2016 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package amqp

import (
	"fmt"
	"time"

	AMQP "github.com/streadway/amqp"
)

// Client connects to an AMQP server
type Client interface {
	Connect() error
	Disconnect()
	IsConnected() bool
	NewPublisher(exchange string) Publisher
}

// DefaultClient is the default AMQP client for The Things Network
type DefaultClient struct {
	url  string
	ctx  Logger
	conn *AMQP.Connection
}

var (
	// ConnectRetries says how many times the client should retry a failed connection
	ConnectRetries = 10
	// ConnectRetryDelay says how long the client should wait between retries
	ConnectRetryDelay = time.Second
)

// NewClient creates a new DefaultClient
func NewClient(ctx Logger, username, password, host string) Client {
	if ctx == nil {
		ctx = &noopLogger{}
	}
	credentials := "guest:guest"
	if username != "" {
		if password != "" {
			credentials = fmt.Sprintf("%s:%s", username, password)
		} else {
			credentials = username
		}
	}
	return &DefaultClient{
		ctx: ctx,
		url: fmt.Sprintf("amqp://%s@%s", credentials, host),
	}
}

// Connect to the AMQP server. It will retry for ConnectRetries times with a delay of ConnectRetryDelay between retries
func (c *DefaultClient) Connect() error {
{'fraction_non_alphanumeric': 0.09127864005912786, 'fraction_numerical': 0.004434589800443459, 'mean_word_length': 3.957875457875458, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2170131', 'n_tokens_mistral': 853, 'n_tokens_neox': 803, 'n_words': 319}