houseofcat / turbocookedrabbit

A user friendly RabbitMQ library written in Golang.
MIT License
107 stars 20 forks source link

I executed according to the case in example, but it didn't run successfully #23

Closed jettjia closed 3 years ago

jettjia commented 3 years ago

config.json:

{
  "EncryptionConfig": {
    "Enabled": false,
    "Type": "aes",
    "TimeConsideration": 1,
    "Threads": 2
  },
  "CompressionConfig": {
    "Enabled": false,
    "Type": "gzip"
  },
  "PoolConfig": {
    "URI": "amqp://admin:123456@10.4.7.71:5672/",
    "ApplicationName": "TurboCookedRabbit",
    "SleepOnErrorInterval": 100,
    "MaxCacheChannelCount": 50,
    "MaxConnectionCount": 10,
    "Heartbeat": 6,
    "ConnectionTimeout": 10,
    "TLSConfig": {
      "EnableTLS": false,
      "PEMCertLocation": "test/catest.pem",
      "LocalCertLocation": "client/cert.ca",
      "CertServerName": "hostname-in-cert"
    }
  },
  "ConsumerConfigs": {},
  "PublisherConfig": {
    "AutoAck": false,
    "SleepOnIdleInterval": 0,
    "SleepOnErrorInterval": 0,
    "PublishTimeOutInterval": 500,
    "MaxRetryCount": 5
  }
}

producer.go

func main() {

    config, err := tcr.ConvertJSONFileToConfig("16-amqp/rabbitmq/00-rabbitmq/config.json") // Load Configuration On Startup
    if err != nil {
        log.Fatal(err)
    }

    rabbitService, err := tcr.NewRabbitService(config, "", "", nil, nil)
    if err != nil {
        log.Fatal(err)
    }

    id, err := uuid.NewUUID()
    if err != nil {
        log.Fatal(err)
    }
    // Then publish (this time with a confirmation/context)
    ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
    defer cancel()
    rabbitService.Publisher.PublishWithConfirmationContext(
        ctx,
        &tcr.Letter{
            LetterID: id,
            Body:     []byte("Hello World"),
            Envelope: &tcr.Envelope{
                Exchange:     "exchangeName",
                RoutingKey:   "routingKey/queueName",
                ContentType:  "text/plain",
                Mandatory:    false,
                Immediate:    false,
                DeliveryMode: 2,
            },
        })

    fmt.Println("create success")

}
houseofcat commented 3 years ago

Well, it wouldn't if you don't put in an exchange name and/or queuename?

Exchange:     "exchangeName",
RoutingKey:   "routingKey/queueName",

Should be

Exchange:     "MyDeclaredExchangeName",
RoutingKey:   "MyDeclaredQueueName",

Or

Exchange:     "",
RoutingKey:   "MyDeclaredQueueName",

I would read up on RabbitMQ and look at the other tests to get a feel for what you are supposed to do. This library is helpful but doesn't replace knowing what you need for the basics of working with RabbitMQ.

https://rabbitmq.com/getstarted.html