alekitto / messenger-extra

Additional transports and serializer support for symfony messenger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bulk write failed due to previous MongoDB\\Driver\\Exception\\AuthenticationException: Authentication failed

cnizzardini opened this issue · comments

What is the proper format for messenger.yaml?

Stack Trace

{
  "@context": "/contexts/Error",
  "@type": "hydra:Error",
  "hydra:title": "BulkWriteException",
  "hydra:description": "Bulk write failed due to previous MongoDB\\Driver\\Exception\\AuthenticationException: Authentication failed.",
  "trace": [
    {
      "namespace": "",
      "short_class": "",
      "class": "",
      "type": "",
      "function": "",
      "file": "/var/www/cpic/vendor/mongodb/mongodb/src/Operation/InsertOne.php",
      "line": 134,
      "args": []
    },
    {
      "namespace": "MongoDB\\Driver",
      "short_class": "Server",
      "class": "MongoDB\\Driver\\Server",
      "type": "->",
      "function": "executeBulkWrite",
      "file": "/var/www/cpic/vendor/mongodb/mongodb/src/Operation/InsertOne.php",
      "line": 134,
      "args": [
        [
          "string",
          "itcollect.messenger"
        ],
        [
          "object",
          "MongoDB\\Driver\\BulkWrite"
        ],
        [
          "array",
          []
        ]
      ]
    },
    {
      "namespace": "MongoDB\\Operation",
      "short_class": "InsertOne",
      "class": "MongoDB\\Operation\\InsertOne",
      "type": "->",
      "function": "execute",
      "file": "/var/www/cpic/vendor/mongodb/mongodb/src/Collection.php",
      "line": 931,
      "args": [
        [
          "object",
          "MongoDB\\Driver\\Server"
        ]
      ]
    },
    {
      "namespace": "MongoDB",
      "short_class": "Collection",
      "class": "MongoDB\\Collection",
      "type": "->",
      "function": "insertOne",
      "file": "/var/www/cpic/vendor/kcs/messenger-extra/lib/Transport/Mongo/MongoSender.php",
      "line": 103,

YAML:

# messenger.yaml

framework:
    messenger:
        # Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
        # failure_transport: failed

        transports:
            mongo: 'mongodb://root:root@192.168.64.100:27017/mydbname?authSource=mydbname'

        routing:
            'App\Message\RebaseLineAuditMessage': mongo

The mongo DSN seems correct.
Authentication failed could indicate that user/password pair is wrong or you are authenticating against the wrong database.

Have you checked mongo debug logs to see what's happening on that end?

Given:

queue: 'mongodb://root:root@192.168.64.100:27017/mydbname/queue?authSource=admin'

mongod.log:

{"t":{"$date":"2021-04-29T16:04:14.740+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.20.0.1:39200","connectionId":92,"connectionCount":22}}
{"t":{"$date":"2021-04-29T16:04:14.755+00:00"},"s":"I",  "c":"ACCESS",   "id":20251,   "ctx":"conn92","msg":"Supported SASL mechanisms requested for unknown user","attr":{"user":"root@mydbname"}}
{"t":{"$date":"2021-04-29T16:04:14.756+00:00"},"s":"I",  "c":"ACCESS",   "id":20249,   "ctx":"conn92","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-256","principalName":"root","authenticationDatabase":"mydbname","client":"172.20.0.1:39200","result":"UserNotFound: Could not find user \"root\" for db \"mydbname\""}}
{"t":{"$date":"2021-04-29T16:04:14.762+00:00"},"s":"I",  "c":"ACCESS",   "id":20249,   "ctx":"conn92","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","principalName":"root","authenticationDatabase":"mydbname","client":"172.20.0.1:39200","result":"UserNotFound: Could not find user \"root\" for db \"mydbname\""}}
{"t":{"$date":"2021-04-29T16:04:14.765+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn92","msg":"Connection ended","attr":{"remote":"172.20.0.1:39200","connectionId":92,"connectionCount":21}}

You are not using the authSource correctly (at all) in MongoTransportFactory.php