Commit Graph

593 Commits

Author SHA1 Message Date
David Ansari c82dbfd1bb Add missing MQTT test assertion
util:expect_publishes/3 returns 'ok' or
{'publish_not_received', Payload}
2023-06-13 09:40:03 +00:00
David Ansari f485e51d80 Fix Native MQTT crash if properties encoded
Fixes https://github.com/rabbitmq/rabbitmq-server/discussions/8252

The MQTT connection must decode AMQP 0.9.1 properties as they are
getting encoded for example in:
712c2b9ec9/deps/rabbit/src/rabbit_variable_queue.erl (L2219)
and
712c2b9ec9/deps/rabbit/src/rabbit_quorum_queue.erl (L1680)

Prior to this commit, the MQTT connection process could crash with:
```
[{rabbit_mqtt_processor,deliver_one_to_client,
     [{{resource,<<"/">>,queue,
           <<"mqtt-subscription-mqtt-explorer-c5351d21qos0">>},
       <0.4546.0>,undefined,false,
       {basic_message,
           {resource,<<"/">>,exchange,<<"amq.topic">>},
           [<<"plant.v1.M3.BCD423.rev.fillStateChangedEvent">>],
           {content,60,none,
               <<80,64,16,97,112,112,108,105,99,97,116,105,111,110,47,
                 106,115,111,110,2,0,0,0,0,100,103,141,186>>,
               rabbit_framing_amqp_0_9_1,
               [<<"{\"plantIdentificationCode\":\"M3/BCD423/rev\",\"isFullSensorTriggered\":false,\"numberOfCarriers\":20,\"maxNumberOfCarriers\":1174,\"numberOfEmpties\":0,\"numberOfCarriersWithPayload\":20,\"numberOfCarriersWithOrder\":0,\"trackLength\":30000,\"trackLengthOccupied\":1130}">>]},
           <<31,230,178,158,209,240,53,221,100,60,64,5,227,237,58,21>>,
           true}},
      false,
      {state,
          {cfg,#Port<0.282>,mqtt311,true,undefined,
              {resource,<<"/">>,exchange,<<"amq.topic">>},
              undefined,false,none,<0.680.0>,flow,none,10,<<"/">>,
              <<"mqtt-explorer-c5351d21">>,undefined,
              {192,168,10,131},
              1883,
              {192,168,10,130},
              53244,1684508087392,#Fun<rabbit_mqtt_reader.0.106886>},
          {rabbit_queue_type,
              #{{resource,<<"/">>,queue,
                    <<"mqtt-subscription-mqtt-explorer-c5351d21qos0">>} =>
                    {ctx,rabbit_classic_queue,
                        {rabbit_classic_queue,<0.4546.0>,#{},
                            #{<0.4546.0> => ok}}}}},
          #{},#{},1,
          #{<<"#">> => 0,<<"$SYS/#">> => 0},
          {auth_state,
              {user,<<"rabbit">>,[],
                  [{rabbit_auth_backend_internal,
                       #Fun<rabbit_auth_backend_internal.3.114557357>}]},
              #{<<"client_id">> => <<"mqtt-explorer-c5351d21">>}},
          registered,#{},0}],
     [{file,"rabbit_mqtt_processor.erl"},{line,1414}]},
 {lists,foldl,3,[{file,"lists.erl"},{line,1350}]},
 {rabbit_mqtt_processor,handle_queue_event,2,
     [{file,"rabbit_mqtt_processor.erl"},{line,1345}]},
 {rabbit_mqtt_reader,handle_cast,2,
     [{file,"rabbit_mqtt_reader.erl"},{line,134}]},
 {gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,1123}]},
 {gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,1200}]},
 {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]}
```
2023-05-19 17:05:31 +00:00
David Ansari 044f6e3bac Move plugin rabbitmq-message-timestamp to the core
As reported in https://groups.google.com/g/rabbitmq-users/c/x8ACs4dBlkI/
plugins that implement rabbit_channel_interceptor break with
Native MQTT in 3.12 because Native MQTT does not use rabbit_channel anymore.
Specifically, these plugins don't work anymore in 3.12 when sending a message
from an MQTT publisher to an AMQP 0.9.1 consumer.

Two of these plugins are
https://github.com/rabbitmq/rabbitmq-message-timestamp
and
https://github.com/rabbitmq/rabbitmq-routing-node-stamp

This commit moves both plugins into rabbitmq-server.
Therefore, these plugins are deprecated starting in 3.12.

Instead of using these plugins, the user gets the same behaviour by
configuring rabbitmq.conf as follows:
```
incoming_message_interceptors.set_header_timestamp.overwrite = false
incoming_message_interceptors.set_header_routing_node.overwrite = false
```

While both plugins were incompatible to be used together, this commit
allows setting both headers.

We name the top level configuration key `incoming_message_interceptors`
because only incoming messages are intercepted.
Currently, only `set_header_timestamp` and `set_header_routing_node` are
supported. (We might support more in the future.)
Both can set `overwrite` to `false` or `true`.
The meaning of `overwrite` is the same as documented in
https://github.com/rabbitmq/rabbitmq-message-timestamp#always-overwrite-timestamps
i.e. whether headers should be overwritten if they are already present
in the message.

Both `set_header_timestamp` and `set_header_routing_node` behave exactly
to plugins `rabbitmq-message-timestamp` and `rabbitmq-routing-node-stamp`,
respectively.

Upon node boot, the configuration is put into persistent_term to not
cause any performance penalty in the default case where these settings
are disabled.

The channel and MQTT connection process will intercept incoming messages
and - if configured - add the desired AMQP 0.9.1 headers.

For now, this allows using Native MQTT in 3.12 with the old plugins
behaviour.

In the future, once "message containers" are implemented,
we can think about more generic message interceptors where plugins can be
written to modify arbitrary headers or message contents for various protocols.

Likewise, in the future, once MQTT 5.0 is implemented, we can think
about an MQTT connection interceptor which could function similar to a
`rabbit_channel_interceptor` allowing to modify any MQTT packet.
2023-05-15 08:37:52 +00:00
David Ansari 967e262272 Add MQTT client id to connection closed event
As requested in https://github.com/rabbitmq/rabbitmq-server/discussions/6331#discussioncomment-5796154
include all infos that were emitted in the MQTT connection created event also
in the MQTT connection closed event.
This ensures infos such as MQTT client ID are part of the connection
closed event.
Therefore, it's easy for the user to correlate between the two event
types.
Note that the MQTT plugin emits connection created and connection closed events only if
the CONNECT packet was successfully processed, i.e.authentication was successful.

Remove the disconnected_at property because it was never used.
rabbit_event already adds a timestamp to any event.
2023-05-04 09:15:55 +00:00
David Ansari 83eede7ef2 Keep storing MQTT client IDs as lists in Ra
Up to 3.11.x an MQTT client ID is tracked in Ra
as a list of bytes as returned by binary_to_list/1 in
48467d6e12/deps/rabbitmq_mqtt/src/rabbit_mqtt_frame.erl (L137)

This has two downsides:
1. Lists consume more memory than binaries (when tracking many clients).
2. It violates the MQTT spec which states
   "The ClientId MUST be a UTF-8 encoded string as defined in Section 1.5.3 [MQTT-3.1.3-4]." [v4 3.1.3.1]

Therefore, the original idea was to always store MQTT client IDs as
binaries starting with Native MQTT in 3.12.
However, this leads to client ID tracking misbehaving in mixed version
clusters since new nodes would register client IDs as binaries and old
nodes would register client IDs as lists. This means that a client
registering on a new node with the same client ID as a connection to the
old node did not terminate the connection on the old node.

Therefore, for backwards compatibility, we leave the client ID as a list of bytes
in the Ra machine state because the feature flag delete_ra_cluster_mqtt_node
introduced in v3.12 will delete the Ra cluster anyway and
the new client ID tracking via pg local will store client IDs as
binaries.

An interesting side note learned here is that the compiled file
rabbit_mqtt_collector must not be changed. This commit only modifies
function specs. However as soon as the compiled code is changed, this
module becomes a new version. The new version causes the anonymous ra query
function to fail in mixed clusters: When the old node does a
ra:leader_query where the leader is on the new node, the query function
fails on the new node with `badfun` because the new node does not have
the same module version. For more context, read:
https://web.archive.org/web/20181017104411/http://www.javalimit.com/2010/05/passing-funs-to-other-erlang-nodes.html
2023-04-28 07:57:23 +00:00
Michael Klishin 686fb9a4e9
Merge pull request #7966 from rabbitmq/otp26-compatibility
OTP26 compatibility: `{verify_none}`
2023-04-24 18:03:49 +04:00
David Ansari e514f85c71 Bump test cluster creation timeouts
in MQTT tests.

For example in the ff_SUITE wee see in Buildbuddy sporadic
failures that the cluster cannot be created within 2 minutes:

```
*** CT Error Notification 2023-04-24 10:58:55.628 ***🔗
rabbit_ct_helpers:port_receive_loop failed on line 945
Reason: {timetrap_timeout,120000}

...

=== Ended at 2023-04-24 10:58:55
=== Location: [{rabbit_ct_helpers,port_receive_loop,945},
              {rabbit_ct_helpers,exec,920},
              {rabbit_ct_broker_helpers,cluster_nodes1,858},
              {rabbit_ct_broker_helpers,cluster_nodes1,840},
              {rabbit_ct_helpers,run_steps,141},
              {ff_SUITE,init_per_group,last_expr},
              {test_server,ts_tc,1782},
              {test_server,run_test_case_eval1,1379},
              {test_server,run_test_case_eval,1223}]
=== Reason: timetrap timeout
===
*** init_per_group failed.
    Skipping all cases.
```

The default time limit for a test case is 30 minutes.
2023-04-24 15:23:15 +02:00
Michal Kuratczyk d04b3afe9b verify_none in a couple of tests 2023-04-24 13:11:44 +00:00
David Ansari d670a7c50e Make test rabbit_mqtt_qos0_queue_overflow less flaky
Similarly to https://github.com/rabbitmq/rabbitmq-server/pull/7663,
increase the message size and decrease the client buffer sizes.

This change is needed because we switched from erlang:port_command/2 to
gen_tcp:send/2. The former is a bit more asynchronous than the latter
because the latter waits for the inet_reply from the port.
2023-04-17 15:06:53 +00:00
David Ansari 0130d3ac36 Clean up exclusive durable queues after unclean shutdown
What:

Delete bindings of exclusive durable queues after an
unclean shutdown.

Why:

Native MQTT in 3.12 uses only durable queues to ease transition to
Khepri. Since auto-delete queues are not deleted after an unclean
shutdown, Native MQTT uses exclusive (instead of auto-delete) queues
for clean sessions.

While this bug is not specific to Native MQTT, this bug is most relevant
for the upcoming 3.12 release since exclusive durable queues are rarely used
otherwise.

How:

During queue recovery, not all bindings are recovered yet.
Therefore, if, during queue recovery, an exclusive, durable queue need to
be deleted, only durable bindings should be queried.

Queue types need to make sure that their exclusive, durable queues including their
bindings are deleted before starting with binding recovery.
Otherwise binding deletion and binding recovery get interleaved leading to topic
bindings being created and left behind.
Therefore, a classic queue process replies to the recovery process after it
deleted its queue record and associated bindings from the database.
2023-03-23 21:59:19 +00:00
David Ansari f5564da94a Fix flaky test rabbit_mqtt_qos0_queue_overflow
The test always succeeds on `main` branch.

The test also always succeeds on `mc` branch when running remotely:
```
bazel test //deps/rabbitmq_mqtt:reader_SUITE --test_env FOCUS="-group tests -case rabbit_mqtt_qos0_queue_overflow" --config=rbe-25 -t- --runs_per_test=50
```

However, the test flakes when running on `mc` branch locally on the MAC:
```
make -C deps/rabbitmq_mqtt ct-reader t=tests:rabbit_mqtt_qos0_queue_overflow FULL=1
```
with the following local changes:
```
~/workspace/rabbitmq-server/deps/rabbitmq_mqtt mc *6 !1 >                                                                                                                                                                                                                                                  3s direnv rb 2.7.2
diff --git a/deps/rabbitmq_mqtt/test/reader_SUITE.erl b/deps/rabbitmq_mqtt/test/reader_SUITE.erl
index fb71eae375..21377a2e73 100644
--- a/deps/rabbitmq_mqtt/test/reader_SUITE.erl
+++ b/deps/rabbitmq_mqtt/test/reader_SUITE.erl
@@ -27,7 +27,7 @@ all() ->

 groups() ->
     [
-     {tests, [],
+     {tests, [{repeat_until_any_fail, 30}],
       [
        block_connack_timeout,
        handle_invalid_packets,
@@ -43,7 +43,7 @@ groups() ->
     ].

 suite() ->
-    [{timetrap, {seconds, 60}}].
+    [{timetrap, {minutes, 60}}].

 %% -------------------------------------------------------------------
 %% Testsuite setup/teardown.
```
failes prior to this commit after the 2nd time and does not fail after
this commit.
2023-03-17 15:54:33 +00:00
David Ansari d72ff9248b Expose mqtt.mailbox_soft_limit via Cuttlefish 2023-03-07 14:35:28 +01:00
David Ansari dd372619f8 Add missing exchange write access check
when an MQTT will message is published.
2023-03-02 10:25:07 +01:00
David Ansari 0058380fbd Web MQTT: Send CONNACK error code before closing connection
"If the Client supplies a zero-byte ClientId with CleanSession set to 0,
the Server MUST respond to the CONNECT Packet with a CONNACK return code 0x02
(Identifier rejected) and then close the Network Connection" [MQTT-3.1.3-8].

In Web MQTT, the CONNACK was not sent to the client because the Web MQTT
connection process terminated before being sending the CONNACK to the
client.
2023-02-28 10:33:57 +01:00
David Ansari 2dc45e8084 Fix flaky MQTT Java test
Every ~30 runs, test case `sessionRedelivery` was failing with error:
```
[ERROR] sessionRedelivery{TestInfo}  Time elapsed: 1.298 s  <<< ERROR!
org.eclipse.paho.client.mqttv3.MqttException: Client is currently disconnecting
	at com.rabbitmq.mqtt.test.MqttTest.sessionRedelivery(MqttTest.java:535)
```

The problem was that the Java client was still in connection state
`DISCONNECTING` which throws a Java exception when `connect()`ing.

So, the problem was client side.

We already check for `isConnected()` to be `false` which internally
checks for
```
conState == CONNECTED
```
However, there is no public client API to check for other connection
states. Therefore just waiting for a few milliseconds fixes the flake.
2023-02-20 10:42:18 +01:00
David Ansari b165adb958 Add timeout for test AMQP 0.9.1 connection to open
We see sporadic test failures where a test case hangs in the
receive until the Bazel suite timeout is reached.

There is no point in a test case to wait forever for an AMQP 0.9.1
connection to establish. Let's time out after 1 minute.

This will make the test case fail faster.
2023-02-16 19:25:06 +01:00
David Ansari efa56bf0cc Fix flaky test
Very rarely, the assertion failed with
```
=== Ended at 2023-02-13 13:25:52
=== Location: [{shared_SUITE,global_counters,590},
              {test_server,ts_tc,1782},
              {test_server,run_test_case_eval1,1291},
              {test_server,run_test_case_eval,1223}]
=== === Reason: {assertEqual,
                     [{module,shared_SUITE},
                      {line,590},
                      {expression,"get_global_counters ( Config , ProtoVer )"},
                      {expected,
                          #{consumers => 0,messages_confirmed_total => 2,
                            messages_received_confirm_total => 2,
                            messages_received_total => 5,
                            messages_routed_total => 3,
                            messages_unroutable_dropped_total => 1,
                            messages_unroutable_returned_total => 1,
                            publishers => 0}},
                      {value,
                          #{consumers => 1,messages_confirmed_total => 2,
                            messages_received_confirm_total => 2,
                            messages_received_total => 5,
                            messages_routed_total => 3,
                            messages_unroutable_dropped_total => 1,
                            messages_unroutable_returned_total => 1,
                            publishers => 1}}]}
  in function  shared_SUITE:global_counters/2 (shared_SUITE.erl, line 590)
  in call from test_server:ts_tc/3 (test_server.erl, line 1782)
  in call from test_server:run_test_case_eval1/6 (test_server.erl, line 1291)
  in call from test_server:run_test_case_eval/9 (test_server.erl, line 1223)
```

The DISCONNECT packet is sent one-way from client to server.
2023-02-13 14:14:14 +00:00
David Ansari 700c122f9e Add test that MQTT ingores configured default queue type
The queue type being created for MQTT connections is solely determined
by the rabbitmq_mqtt plugin, not by per vhost defaults.

If the per vhost default queue type is configured to be a quorum queue,
we still want to create classic queues for MQTT connections.
2023-02-09 19:18:34 +01:00
David Ansari bd50a41d67 Decrease MQTT mailbox_soft_limit
Let's decrease the mailbox_soft_limit from 1000 to 200.
Obviously, both values are a bit arbitrary.
However, MQTT workloads usually do not have high throughput patterns for
a single MQTT connection. The only valid scenario where an MQTT
connections' process mailbox could have many messages is in large fan-in
scenarios where many MQTT devices sending messages at once to a single MQTT
device - which is rather unusual.

It makes more sense to protect against cluster wide memory alarms by
decreasing the mailbox_soft_limit.
2023-02-09 19:18:34 +01:00
David Ansari 3cd7d80d04 Enable feature flag in test case
Always enable feature flag rabbit_mqtt_qos0_queue
in test case rabbit_mqtt_qos0_queue_overflow because this test case does
not make sense without the mqtt_qos0 queue type.

Note that enabling the feature flag should always succeed because this
test case runs on a single node, and therefore on a new version in mixed
version tests.
2023-02-09 11:17:52 +00:00
David Ansari 91b56bd85d Remove mixed version check in MQTT tests
In the MQTT test assertions, instead of checking whether the test runs
in mixed version mode where all non-required feature flags are disabled
by default, check whether the given feature flag is enabled.

Prior to this commit, once feature flag rabbit_mqtt_qos0_queue becomes
required, the test cases would have failed.
2023-02-09 10:53:50 +00:00
David Ansari 327e3da8cb Run MQTT maintenance test in mixed version cluster
Nowadays, the old RabbitMQ nodes in mixed version cluster
tests on `main` branch run in version 3.11.7.

Since maintenance mode was wrongly closing cluster-wide MQTT connections
only in RabbitMQ <3.11.2 (and <3.10.10), we can re-enable this mixed
version test.
2023-02-08 16:26:10 +01:00
David Ansari 146570df5e Delete AMQP 0.9.1 header x-mqtt-dup
AMQP 0.9.1 header x-mqtt-dup was determined by the incoming MQTT PUBLISH
packet's DUP flag. Its only use was to determine the outgoing MQTT
PUBLISH packet's DUP flag. However, that's wrong behaviour because
the MQTT 3.1.1 protocol spec mandates:
"The value of the DUP flag from an incoming PUBLISH packet is not
propagated when the PUBLISH Packet is sent to subscribers by the Server.
The DUP flag in the outgoing PUBLISH packet is set independently to the
incoming PUBLISH packet, its value MUST be determined solely by whether
the outgoing PUBLISH packet is a retransmission."
[MQTT-3.3.1-3]

Native MQTT fixes this wrong behaviour. Therefore, we can delete this
AMQP 0.9.1 header.
2023-02-07 16:36:08 +01:00
David Ansari 5f6a1f96ca Remove unused NodeId parameter 2023-02-07 16:36:08 +01:00
David Ansari bec8f9a21c Support topic variable expansion for vhost and username
Native MQTT introduced a regression where the "{username}" and "{vhost}"
variables were not expanded in permission patterns.

This regression was unnoticed because the java_SUITE's
topicAuthorisationVariableExpansion test was wrongfully passing because
its topic started with "test-topic" which matched another allow listed
topic (namely "test-topic") instead of the pattern
"{username}.{client_id}.a".
This other java_SUITE regression got introduced by commit
26a17e8530

This commit fixes both the buggy Java test and the actual regression
introduced in Native MQTT.
2023-02-07 16:36:08 +01:00
David Ansari 1ba4823495 Delete unused files 2023-02-07 16:36:08 +01:00
David Ansari 79c12b60bc Use maybe expression instead of messy patterns
This commit is pure refactoring making the code base more maintainable.

Replace rabbit_misc:pipeline/3 with the new OTP 25 experimental maybe
expression because
"Frequent ways in which people work with sequences of failable
operations include folds over lists of functions, and abusing list
comprehensions. Both patterns have heavy weaknesses that makes them less
than ideal."
https://www.erlang.org/eeps/eep-0049#obsoleting-messy-patterns

Additionally, this commit is more restrictive in the type spec of
rabbit_mqtt_processor state fields.
Specifically, many fields were defined to be `undefined | T` where
`undefined` was only temporarily until the first CONNECT packet was
processed by the processor.
It's better to initialise the MQTT processor upon first CONNECT packet
because there is no point in having a processor without having received
any packet.
This allows many type specs in the processor to change from `undefined |
T` to just `T`.
Additionally, memory is saved by removing the `received_connect_packet`
field from the `rabbit_mqtt_reader` and `rabbit_web_mqtt_handler`.
2023-02-07 16:36:08 +01:00
David Ansari 02cf072ae4 Restrict MQTT CONNECT packet size
In MQTT 3.1.1, the CONNECT packet consists of
1. 10 bytes variable header
2. ClientId (up to 23 bytes must be supported)
3. Will Topic
4. Will Message (maximum length 2^16 bytes)
5. User Name
6. Password

Restricting the CONNECT packet size to 2^16 = 65,536 bytes
seems to be a reasonalbe default.

The value is configurable via the MQTT app parameter
`max_packet_size_unauthenticated`.

(Instead of being called `max_packet_size_connect`) the
name `max_packet_size_unauthenticated` is generic
because MQTT 5 introduces an AUTH packet type.
2023-01-29 15:00:19 +00:00
Chunyi Lyu 209f23fa2f
Revert "Format MQTT code with `erlfmt`" 2023-01-27 18:25:57 +00:00
Chunyi Lyu 1de9fcf582 Format mqtt files with erlfmt 2023-01-27 11:06:41 +00:00
David Ansari 9c2f5975ea Support tracing in Native MQTT 2023-01-24 17:32:59 +00:00
David Ansari 437cbb73be Use delegate for stateless deliveries
For example when at-most-once dead lettering does a fan out to many
target classic queues this commit will reduce inter-node data traffic by
using delegate.
2023-01-24 17:32:59 +00:00
David Ansari a4db85de0d Make pipeline fail when there are dialyzer warnings
We want the build to fail if there are any dialyzer warnings in
rabbitmq_mqtt or rabbitmq_web_mqtt. Otherwise we rely on people manually
executing and checking the results of dialyzer.

Also, we want any test to fail that is flaky.
Flaky tests can indicate subtle errors in either test or program execution.
Instead of marking them as flaky, we should understand and - if possible -
fix the underlying root cause.

Fix OTP 25.0 dialyzer warning

Type gen_server:format_status() is known in OTP 25.2, but not in 25.0
2023-01-24 17:32:59 +00:00
David Ansari dcb00f1324 Reduce test load
Run test either on a RabbitMQ cluster of size 1 or size 3.
Running a test on both cluster sizes does not result in higher test
coverage.
This puts less pressure on Buildbuddy and reduces overall test
execution time.
2023-01-24 17:32:59 +00:00
David Ansari f46f0541ea Fix "Clean Session" state for QoS 0 subscriptions
Up to RabbitMQ 3.11, the following bug existed.

The MQTT 3.1.1. protocol spec mandates:
```
The Session state in the Server consists of:
* The Client’s subscriptions.
* ...
```

However, because QoS 0 queues were auto-delete up to 3.11 (or exclusive
prior to this commit), QoS 0 queues and therefore their bindings were
deleted when a non-clean session terminated.

When the same client re-connected, its QoS 0 subscription was lost.
Note that storing **messages** for QoS 0 subscription is optional while the
client is disconnected. However, storing the subscription itself (i.e.
bindings in RabbitMQ terms) is not optional: The client must receive new
messages for its QoS 0 subscriptions after it reconnects without having
to send a SUBSCRIBE packet again.

"After the disconnection of a Session that had CleanSession set to 0,
the Server MUST store further QoS 1 and QoS 2 messages that match any
subscriptions that the client had at the time of disconnection as part
of the Session state [MQTT-3.1.2-5]. It MAY also store QoS 0 messages
that meet the same criteria."
This commit additionally implements the last sentence.
2023-01-24 17:32:59 +00:00
David Ansari 863b7ea16a Include non-AMQP connections in connection count
Prior to this commit:
```
rabbitmqctl status
...
Totals

Connection count: 0
Queue count: 64308
Virtual host count: 1
...
```
only counted AMQP connections, but did not include MQTT or stream
connections.

Let's include the count of all connections in the output of
`rabbitmqctl status`.
2023-01-24 17:32:59 +00:00
David Ansari a341912b75 Expand clean_session=false test 2023-01-24 17:32:59 +00:00
David Ansari 9283b4f4f6 Add test AMQP 0.9.1 to MQTT with QoS 0 2023-01-24 17:32:59 +00:00
David Ansari fb93a3c17d Block only publishing (Web) MQTT connections
When a cluster wide memory or disk alarm is fired, in AMQP 0.9.1 only
connections that are publishing messages get blocked.
Connections that only consume can continue to empty the queues.

Prior to this commit, all MQTT connections got blocked during a memory
or disk alarm. This has two downsides:
1. MQTT connections that only consume, but never published, cannot empty
   queues anymore.
2. If the memory or disk alarm takes long, the MQTT client does not
   receive a PINGRESP from the server when it sends a PINGREQ potentially
   leading to mass client disconnection (depending on the MQTT client
   implementation).

This commit makes sure that an MQTT connection that never sent a single
PUBLISH packet (e.g. "pure" MQTT subscribers) are not blocked during
memory or disk alarms.

In contrast to AMQP 0.9.1, new connections are still blocked from being
accepted because accepting (many) new MQTT connections also lead to
increased resource usage.

The implemenation as done in this commit is simpler, but also more naive
than the logic in rabbit_reader: rabbit_reader blocks connections more
dynamically whereas rabbit_mqtt_reader and rabbit_web_mqtt_handler
block a connection if the connection ever sent a single PUBLISH packet
during its lifetime.
2023-01-24 17:32:59 +00:00
David Ansari d651f87ea7 Share tests between MQTT and Web MQTT
New test suite deps/rabbitmq_mqtt/test/shared_SUITE contains tests that
are executed against both MQTT and Web MQTT.

This has two major advantages:
1. Eliminates test code duplication between rabbitmq_mqtt and
rabbitmq_web_mqtt making the tests easier to maintain and to understand.
2. Increases test coverage of Web MQTT.

It's acceptable to add a **test** dependency from rabbitmq_mqtt to
rabbitmq_web_mqtt. Obviously, there should be no such dependency
for non-test code.
2023-01-24 17:32:59 +00:00
David Ansari 7c1aa49361 Increase MQTT test coverage and fix edge cases 2023-01-24 17:32:59 +00:00
David Ansari c9df098f5c Handle topic, username, password as binaries
Topic, username, and password are parsed as binaries.
Storing topics as lists or converting between
lists and binaries back and forth several times is
unnecessary and expensive.
2023-01-24 17:32:59 +00:00
David Ansari fb6c8da2fc Block Web MQTT connection if memory or disk alarm
Previously (until RabbitMQ v3.11.x), a memory or disk alarm did
not block the Web MQTT connection because this feature was only
implemented half way through: The part that registers the Web MQTT
connection with rabbit_alarm was missing.
2023-01-24 17:32:59 +00:00
David Ansari a8b69b43c1 Fix dialyzer issues and add function specs
Fix all dialyzer warnings in rabbitmq_mqtt and rabbitmq_web_mqtt.

Add more function specs.
2023-01-24 17:32:58 +00:00
David Ansari 1720aa0e75 Allow CLI listing rabbit_mqtt_qos0_queue queues 2023-01-24 17:30:10 +00:00
David Ansari 56e97a9142 Fix MQTT in management plugin
1. Allow to inspect an (web) MQTT connection.
2. Show MQTT client ID on connection page as part of client_properties.
3. Handle force_event_refresh (when management_plugin gets enabled
   after (web) MQTT connections got created).
4. Reduce code duplication between protocol readers.
5. Display '?' instead of 'NaN' in UI for absent queue metrics.
6. Allow an (web) MQTT connection to be closed via management_plugin.

For 6. this commit takes the same approach as already done for the stream
plugin:
The stream plugin registers neither with {type, network} nor {type,
direct}.
We cannot use gen_server:call/3 anymore to close the connection
because the web MQTT connection cannot handle gen_server calls (only
casts).
Strictly speaking, this commit requires a feature flag to allow to force
closing stream connections from the management plugin during a rolling
update. However, given that this is rather an edge case, and there is a
workaround (connect to the node directly hosting the stream connection),
this commit will not introduce a new feature flag.
2023-01-24 17:30:10 +00:00
David Ansari bd0acb33e4 Remove test helper util:connect_to_node/3
because this method is superfluous given that util:connect
already exists.
2023-01-24 17:30:10 +00:00
David Ansari 97fefff0fe Add overflow drop-head to rabbit_mqtt_qos_queue type
Traditionally, queue types implement flow control by keeping state in
both sending and receiving Erlang processes (for example credit based flow
control keeps the number of credits within the process dictionary).

The rabbit_mqtt_qos0_queue cannot keep such state in sending or receiving
Erlang process because such state would consume a large amount of memory
in case of large fan-ins or large fan-outs.
The whole idea of the rabbit_mqtt_qos_queue type is to not keep any
state in the rabbit_queue_type client. This makes this new queue
type scale so well.

Therefore the new queue type cannot (easily) implement flow control
throttling individual senders.

In this commit, we take a different approach:
Instead of implementing flow control throttling individual senders,
the receiving MQTT connection process drops QoS 0 messages from the
rabbit_mqtt_qos_queue if it is overflowed with messages AND its MQTT
client is not capable of receiving messages fast enough.

This is a simple and sufficient solution because it's better to drop QoS
0 (at most once) messages instead of causing cluster-wide memory alarms.

The user can opt out of dropping messages by setting the new env setting
mailbox_soft_limit to 0.

Additionally, we reduce the send_timeout from 30 seconds default in
Ranch to 15 seconds default in MQTT. This will detect hanging MQTT
clients faster causing the MQTT connection to be closed.
2023-01-24 17:30:10 +00:00
Chunyi Lyu de28560d8f Extract connect to node helper in rmq mqtt tests 2023-01-24 17:30:10 +00:00
Chunyi Lyu aea7ff8f8d Use helper to connect to node in mqtt cluster suite 2023-01-24 17:30:10 +00:00
David Ansari 61f6ca7b66 Support iodata() when sending message to MQTT client
When the MQTT connection receives an AMQP 0.9.1 message, it will contain
a list of payload fragments.

This commit avoids the expensive operation of turning that list into a binary.

All I/O methods accept iodata():
* erlang:port_command/2
* ssl:send/2
* In Web MQTT, cowboy websockets accept iodata():
0d04cfffa3/src/cow_ws.erl (L58)
2023-01-24 17:30:10 +00:00
David Ansari 15636fdb90 Rename frame to packet
The MQTT protocol specs define the term "MQTT Control Packet".
The MQTT specs never talk about "frame".

Let's reflect this naming in the source code since things get confusing
otherwise:
Packets belong to MQTT.
Frames belong to AMQP 0.9.1 or web sockets.
2023-01-24 17:30:10 +00:00
David Ansari 3980c28596 Allow higher load on Mnesia by default
Prior to this commit, when connecting or disconnecting many thousands of
MQTT subscribers, RabbitMQ printed many times:
```
[warning] <0.241.0> Mnesia('rabbit@mqtt-rabbit-1-server-0.mqtt-rabbit-1-nodes.default'): ** WARNING ** Mnesia is overloaded: {dump_log,write_threshold}
```

Each MQTT subscription causes queues and bindings to be written into Mnesia.

In order to allow for higher Mnesia load, the user can configure
```
[
 {mnesia,[
  {dump_log_write_threshold, 10000}
 ]}
].
```
in advanced.config

or set this value via
```
RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS="-mnesia dump_log_write_threshold 10000"
```

The Mnesia default for dump_log_write_threshold is 1,000.
The Mnesia default for dump_log_time_threshold is 180,000 ms.

It is reasonable to increase the default for dump_log_write_threshold from
1,000 to 5,000 and in return decrease the default dump_log_time_threshold
from 3 minutes to 1.5 minutes.
This way, users can achieve higher MQTT scalability by default.

This setting cannot be changed at Mnesia runtime, it needs to be set
before Mnesia gets started.
Since the rabbitmq_mqtt plugin can be enabled dynamically after Mnesia
started, this setting must therefore apply globally to RabbitMQ.

Users can continue to set their own defaults via advanced.config or
RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS. They continue to be respected
as shown by the new test suite included in this commit.
2023-01-24 17:30:10 +00:00
David Ansari 86de0a1557 Reduce memory usage of MQTT connection process
by removing the two fields referencing a function:
mqtt2amqp_fun and amqp2mqtt_fun

Each field required 1 words + 11 words for the function reference.

Therefore, for 1 million MQTT connections this commit saves:
    (1+11) * 2 * 1,000,000 words
    = 192 MB of memory

In addition, the code is now simpler to understand.

There is no change in behaviour except for the sparkplug environment
variable being read upon application start.

We put the compiled regexes into persistent term because they are the
same for all MQTT connections.
2023-01-24 17:30:10 +00:00
David Ansari f842ffd250 Add feature flag rabbit_mqtt_qos0_queue
Routing to a queue of type rabbit_mqtt_qos0_queue hosted on
a remote node requires knowledge of that queue type on the
local node.
2023-01-24 17:30:10 +00:00
Chunyi Lyu 30a9ea521e Use connect helper func in more mqtt tests
- reduce code duplication
- connect helper does not unlink the connection process by default
2023-01-24 17:30:10 +00:00
David Ansari 7bc8208a1b Remove local record definitions from header files
Record #state{} is purely local to rabbit_mqtt_reader.
Record #proc_state{} is purely local to rabbit_mqtt_processor.

Therefore, move these record definitions to the defining module.
This avoids unnecessarily exposing internal information.

Now, that #proc_state{} is defined in rabbit_mqtt_processor,
rename #proc_state to #state{}.
2023-01-24 17:30:10 +00:00
David Ansari 6815ceb54a Fix mixed version reader_SUITE will test 2023-01-24 17:30:10 +00:00
David Ansari 76f4598d92 Send last will if client did not DISCONNECT
"The Will Message MUST be published when the Network Connection is subsequently
closed unless the Will Message has been deleted by the Server on receipt of a
DISCONNECT Packet [MQTT-3.1.2-8].
Situations in which the Will Message is published include, but are not limited to:
•	An I/O error or network failure detected by the Server.
•	The Client fails to communicate within the Keep Alive time.
•	The Client closes the Network Connection without first sending a DISCONNECT Packet.
•	The Server closes the Network Connection because of a protocol error.
"

Prior to this commit, the will message was not sent in all scenarios
where it should have been sent.

In this commit, the will message is always sent unless the client sent a
DISCONNECT packet to the server.

We achieve this by sending the will message in the terminate callback.

Note that the Reason passed into the terminate callback of
rabbit_web_mqtt_handler is the atom 'stop' (that is, we cannot pass a custom
reason here).

Therefore, in order to know within the terminate callback whether the client
sent a DISCONNECT packet, we have to modify the process state.
Rather than including a new field into the process state record which requires
1 additional word per MQTT connection (i.e. expensive with millions of
MQTT connection processes - we want to keep the process state small),
we intead modify the state just before stopping the process to
{SendWill, State}.
2023-01-24 17:30:10 +00:00
David Ansari 14b3b93b25 Make ff_SUITE less flaky 2023-01-24 17:30:10 +00:00
David Ansari 65bc0c395b Fix global counters
Prior to this commit messages_delivered for queue_type_qos0 is
wrongfully incremented if clean session is false

Also, delete duplicate code.
2023-01-24 17:30:10 +00:00
Chunyi Lyu 075bc06623 Handle messages_delivered_consume_*_ack counters at delivery
- increment messages_delivered_consume_auto_ack if subscribe queue
is type mqtt_qos0 queue or if publising QoS is 0
- increment messages_delivered_consume_manual_ack if both publising
and subcribe are QoS 1
- increment messages_acknowledged at queue_type:settle()
2023-01-24 17:30:10 +00:00
David Ansari 16fa12244e Avoid exceptions in mixed version cluster
1. Avoid following exceptions in mixed version clusters when new MQTT
   connections are created:
```
{{exception,{undef,[{rabbit_mqtt_util,remove_duplicate_clientid_connections,
                                      [{<<"/">>,
                                        <<"publish_to_all_queue_types">>},
                                       <0.1447.0>],
                                      []}]}},
 [{erpc,execute_cast,3,[{file,"erpc.erl"},{line,621}]}]}
```
If feature flag delete_ra_cluster_mqtt_node is disabled, let's still
populate pg with MQTT client IDs such that we don't have to migrate them
from the Ra cluster to pg when we enable the feature flag.
However, for actually closing duplicate MQTT client ID connections, if
that feature flag is disabled, let's rely on the Ra cluster to take care
of it.

2. Write a test ensuring the QoS responses are in the right order when a
   single SUBSCRIBE packet contains multiple subscriptions.
2023-01-24 17:30:10 +00:00
David Ansari 573934259a Consume from queue once
Each MQTT connection consumes from its queue at most once
(unless when failing over).
2023-01-24 17:30:10 +00:00
Chunyi Lyu c3779d9996 Implement message consuming counters in mqtt 2023-01-24 17:30:10 +00:00
David Ansari 6e527fb940 Replace existing subscription
"If a Server receives a SUBSCRIBE Packet containing a Topic Filter
that is identical to an existing Subscription’s Topic Filter then
it MUST completely replace that existing Subscription with a new
Subscription. The Topic Filter in the new Subscription will be
identical to that in the previous Subscription, although its
maximum QoS value could be different. Any existing retained
messages matching the Topic Filter MUST be re-sent, but the flow
of publications MUST NOT be interrupted [MQTT-3.8.4-3]."
2023-01-24 17:30:10 +00:00
David Ansari b2c87c59a0 Minor reformatting and renaming 2023-01-24 17:30:10 +00:00
David Ansari e06d3e7069 Unblock queue when it gets deleted
When a quorum queue or stream gets deleted while the MQTT connection
process (or channel) is blocked by that deleted queue due to soft limit
being exceeded, unblock that queue.

In this commit, an unblock action is also returned with the eol.
2023-01-24 17:30:09 +00:00
Chunyi Lyu 80f8e0754f Implement consumer global counter for clean sess false
- remove has_subs from proc state; query datebase to check
if a connection has subscription or not
2023-01-24 17:29:08 +00:00
David Ansari 016451ee87 Reset application env in MQTT flow tests
so that they run independently of other tests
2023-01-24 17:29:07 +00:00
Chunyi Lyu 0b43f002f5 Remove subscriptions map from proc state in mqtt
- subscriptions information can be retrieved directly from mnesia
- when unsubscribe, we check if there is binding between topic name
and queue (check for both qos0 queue name and qos1 queue name) to
unbind
- added a boolean value has_subs in proc state which will indicate
if connection has any active subscriptions. Used for setting consumer
global counter
2023-01-24 17:29:07 +00:00
David Ansari aad7e1cdf6 Add test for consuming MQTT classic queue going down 2023-01-24 17:29:07 +00:00
David Ansari bda52dbf64 Support consuming classic mirrored queue failover
Some users use classic mirrored queues for MQTT queues by
applying a policy.

Given that classic mirrored queues are deprecated, but still supported
in RabbitMQ 3.x, native MQTT must support classic mirrored queues.
2023-01-24 17:29:07 +00:00
David Ansari b97006c4b9 Output username in connection closed event 2023-01-24 17:29:07 +00:00
David Ansari 16b5ec5659 Add missing unblock stream queue action
Test flow control for all queue types.
2023-01-24 17:29:07 +00:00
David Ansari 7fc2234117 Test ETS and NOOP retained message stores 2023-01-24 17:29:07 +00:00
David Ansari 6533532039 Simplify counters
by storing mqtt310 and mqtt311 atoms directly in the processor state.
2023-01-24 17:29:07 +00:00
David Ansari ab5007a53b Handle queue deletion
Handle deletion of queues correctly that an MQTT connection is
publishing to with QoS 1.
2023-01-24 17:29:07 +00:00
Chunyi Lyu de984d026b Subs from 1 connection counts as 1 consumer in global counter
- rename proc state isPublisher to has_published
- create macro for v3 and v4 mqtt protocol name for global
counters
- sub groups in integration suite
2023-01-24 17:29:07 +00:00
David Ansari 38e5e20bb8 Add tests 2023-01-24 17:29:07 +00:00
Chunyi Lyu 17c5dffe7a Set common global counters for mqtt
- protocols are set to mqtt301 or mqtt311 depends
on protocal version set by client connection
- added boolean isPublisher in proc state to track
if connection was ever used to publish. This is used to
set publisher_create and publisher_delete global counters.
- tests added in integration_SUITE
2023-01-24 17:29:07 +00:00
David Ansari 9fd5704e30 Fix mixed version Web MQTT system tests
In mixed verion tests all non-required feature flags are disabled.
Therefore, MQTT client ID tracking happens in Ra.
The Ra client sends commands asynchronously when registering and
deregistering the client ID.

Also, add more tests.
2023-01-24 17:29:07 +00:00
Chunyi Lyu 96854a8c4c Use emqtt:publish in mqtt tests
- rename publish_qos1 to publish_qos1_timeout
since it's only been used for handling publisher timeout
more gracefully in tests
2023-01-24 17:29:07 +00:00
David Ansari 319af3872e Handle duplicate packet IDs
"If a Client re-sends a particular Control Packet, then it MUST use the
same Packet Identifier in subsequent re-sends of that packet."

A client can re-send a PUBLISH packet with the same packet ID.
If the MQTT connection process already received the original packet and
sent it to destination queues, it will ignore this re-send.

The packet ID will be acked to the publisher once a confirmation from
all target queues is received.

There should be no risk of "stuck" messages within the MQTT connection
process because quorum and stream queue clients re-send the message and
classic queues will send a monitor DOWN message in case they are down.
2023-01-24 17:29:07 +00:00
David Ansari 4c15299196 Delete old emqttc client
Instead use latest emqtt client for Web MQTT tests.
2023-01-24 17:29:07 +00:00
David Ansari 816fedf080 Enable flow control to target classic queue 2023-01-24 17:29:07 +00:00
David Ansari 33bf2150a5 Add test for publishing via MQTT to different queue types 2023-01-24 17:29:07 +00:00
David Ansari 627ea8588a Add rabbit_event tests for MQTT
Add tests that MQTT plugin sends correct events to rabbit_event.

Add event connection_closed.
2023-01-24 17:29:07 +00:00
David Ansari 07ad410d81 Skip queue when MQTT QoS 0
This commit allows for huge fanouts if the MQTT subscriber connects with
clean_session = true and QoS 0. Messages are not sent to a conventional queue.
Instead, messages are forwarded directly from MQTT publisher connection
process or channel to MQTT subscriber connection process.
So, the queue process is skipped.

The MQTT subscriber connection process acts as the queue process.
Its mailbox is a superset of the queue. This new queue type is called
rabbit_mqtt_qos0_queue.
Given that the only current use case is MQTT, this queue type is
currently defined in the MQTT plugin.
The rabbit app is not aware that this new queue type exists.

The new queue gets persisted as any other queue such that routing via
the topic exchange contineues to work as usual. This allows routing
across different protocols without any additional changes, e.g. huge
fanout from AMQP client (or management UI) to all MQTT devices.

The main benefit is that memory usage of the publishing process is kept at
0 MB once garbage collection kicked in (when hibernating the gen_server).
This is achieved by having this queue type's client not maintain any
state. Previously, without this new queue type, the publisher process
maintained state of 500MB to all the 1 million destination queues even
long after stopping sending messages to these queues.

Another big benefit is that no queue process need to be created.
Prior to this commit, with 1 million MQTT subscribers, 3 million Erlang
processes got created: 1 million MQTT connection processes, 1 million classic
queue processes, and 1 million classic queue supervisor processes.
After this commit, only the 1 million MQTT connection processes get
created. Hence, a few GBs of process memory will be saved.

Yet another big benefit is that because the new queue type's client
auto-settles the delivery when sending, the publishing process only
awaits confirmation from queues who potentially have at-least-once
consumers. So, the publishing process is not blocked on sending the
confirm back to the publisher if 1 message is let's say routed to 1
million MQTT QoS 0 subscribers while 1 copy is routed to an important
quorum queue or stream and while a single out of the million MQTT
connection processes is down.

Other benefits include:
* Lower publisher confirm latency
* Reduced inter-node network traffic

In a certain sense, this commit allows RabbitMQ to act as a high scale
and high throughput MQTT router (that obviously can lose messages at any
time given the QoS is 0).
For example, it allows use cases as using RabbitMQ to send messages cheaply
and quickly to 1 million devices that happen to be online at the given
time: e.g. send a notification to any online mobile device.
2023-01-24 17:29:07 +00:00
David Ansari 4b1c2c870b Emit cluster-wide MQTT connection infos
When listing MQTT connections with the CLI, whether feature flag
delete_ra_cluster_mqtt_node is enabled or disabled, in both cases
return cluster wide MQTT connections.

If connection tracking is done in Ra, the CLI target node returns all
connection infos because Ra is aware of all MQTT connections.

If connection tracking is done in (local-only) pg, all nodes return
their local MQTT connection infos.
2023-01-24 17:29:07 +00:00
David Ansari 199238d76e Use pg to track MQTT client IDs
Instead of tracking {Vhost, ClientId} to ConnectionPid mappings in our
custom process registry, i.e. custom local ETS table with a custom
gen_server process managing that ETS table, this commit uses the pg module
because pg is better tested.

To save memory with millions of MQTT client connections, we want to save
the mappings only locally on the node where the connection resides and
therfore not be replicated across all nodes.

According to Maxim Fedorov:
"The easy way to provide per-node unique pg scope is to start it like
pg:start_link(node()). At least that's what we've been doing to have
node-local scopes. It will still try to discover scopes on nodeup from
nodes joining the cluster, but since you cannot have nodes with the
same name in one cluster, using node() for local-only scopes worked
well for us."

So that's what we're doing in this commit.
2023-01-24 17:29:07 +00:00
David Ansari ab8957ba9c Use best-effort client ID tracking
"Each Client connecting to the Server has a unique ClientId"

"If the ClientId represents a Client already connected to
the Server then the Server MUST disconnect the existing
Client [MQTT-3.1.4-2]."

Instead of tracking client IDs via Raft, we use local ETS tables in this
commit.

Previous tracking of client IDs via Raft:
(+) consistency (does the right thing)
(-) state of Ra process becomes large > 1GB with many (> 1 Million) MQTT clients
(-) Ra process becomes a bottleneck when many MQTT clients (e.g. 300k)
    disconnect at the same time because monitor (DOWN) Ra commands get
    written resulting in Ra machine timeout.
(-) if we need consistency, we ideally want a single source of truth,
    e.g. only Mnesia, or only Khepri (but not Mnesia + MQTT ra process)

While above downsides could be fixed (e.g. avoiding DOWN commands by
instead doing periodic cleanups of client ID entries using session interval
in MQTT 5 or using subscription_ttl parameter in current RabbitMQ MQTT config),
in this case we do not necessarily need the consistency guarantees Raft provides.

In this commit, we try to comply with [MQTT-3.1.4-2] on a best-effort
basis: If there are no network failures and no messages get lost,
existing clients with duplicate client IDs get disconnected.

In the presence of network failures / lost messages, two clients with
the same client ID can end up publishing or receiving from the same
queue. Arguably, that's acceptable and less worse than the scaling
issues we experience when we want stronger consistency.

Note that it is also the responsibility of the client to not connect
twice with the same client ID.

This commit also ensures that the client ID is a binary to save memory.

A new feature flag is introduced, which when enabled, deletes the Ra
cluster named 'mqtt_node'.

Independent of that feature flag, client IDs are tracked locally in ETS
tables.
If that feature flag is disabled, client IDs are additionally tracked in
Ra.

The feature flag is required such that clients can continue to connect
to all nodes except for the node being udpated in a rolling update.

This commit also fixes a bug where previously all MQTT connections were
cluster-wide closed when one RabbitMQ node was put into maintenance
mode.
2023-01-24 17:29:07 +00:00
David Ansari 5710a9474a Support MQTT Keepalive in WebMQTT
Share the same MQTT keepalive code between rabbit_mqtt_reader and
rabbit_web_mqtt_handler.

Add MQTT keepalive test in both plugins rabbitmq_mqtt and
rabbitmq_web_mqtt.
2023-01-24 17:29:07 +00:00
David Ansari a02cbb73a1 Get all existing rabbitmq_mqtt tests green 2023-01-24 17:29:07 +00:00
David Ansari 23dac495ad Support QoS 1 for sending and receiving 2023-01-24 17:29:07 +00:00
David Ansari cdd253ee87 Receive many messages from classic queue
Before this commit, a consumer from a classic queue was receiving max
200 messages:
bb5d6263c9/deps/rabbit/src/rabbit_queue_consumers.erl (L24)

MQTT consumer process must give credit to classic queue process
due to internal flow control.
2023-01-24 17:29:07 +00:00
David Ansari 99337b84d3 Emit stats
'connection' field is not needed anymore because it was
previously the internal AMQP connection PID
2023-01-24 17:29:07 +00:00
David Ansari 218ee196c4 Make proxy_protocol tests green 2023-01-24 17:29:07 +00:00
David Ansari 77da78f478 Get most auth_SUITE tests green
Some tests which require clean_start=false
or QoS1 are skipped for now.

Differentiate between v3 and v4:
v4 allows for an error code in SUBACK frame.
2023-01-24 17:29:07 +00:00
David Ansari 73ad3bafe7 Revert maybe expression
rabbit_misc:pipeline looks better and doesn't require experimental
feature
2023-01-24 17:29:07 +00:00
David Ansari f4d1f68212 Move authn / authz into rabbitmq_mqtt 2023-01-24 17:29:07 +00:00
Michael Klishin ec4f1dba7d
(c) year bump: 2022 => 2023 2023-01-01 23:17:36 -05:00
David Ansari 694501b923 Close local MQTT connections when draining node
When a node gets drained (i.e. goes into maintenance mode), only local
connections should be terminated.

However, prior to this commit, all MQTT connections got terminated
cluster-wide when a single node was drained.
2022-10-13 11:14:01 +00:00
Luke Bakken 7fe159edef
Yolo-replace format strings
Replaces `~s` and `~p` with their unicode-friendly counterparts.

```
git ls-files *.erl | xargs sed -i.ORIG -e s/~s>/~ts/g -e s/~p>/~tp/g
```
2022-10-10 10:32:03 +04:00
Péter Gömöri c4b7cd98bf Add login_timeout to mqtt and stomp reader
Similarly to handshake_timeout in amqp reader.
2022-09-12 17:48:48 +02:00
David Ansari 4c997f84bd Fix MQTT protocol version in MQTT tests
This is a follow-up commit of https://github.com/rabbitmq/rabbitmq-server/pull/5693

The allowed values of emqtt client library are:
```
{proto_ver, v3 | v4 | v5}
```

Therefore, `{proto_ver, 3}` did not have any effect and used the default
protocol version v4.

Let's fix the misleading version in our tests and be explicit that
we use v4.
2022-09-06 10:11:53 +02:00
David Ansari ac2a5d3dd3 Upgrade MQTT Erlang client
The rabbitmq_mqtt tests used an outdated MQTT Erlang client.
It was a fork that has not been updated for > 4 years.
This commit upgrades the client to the latest version.
Therefore, we can delete our fork https://github.com/rabbitmq/emqttc.git
2022-08-31 14:12:23 +00:00
David Ansari 49ed70900e Fix failing proxy_protocol test
Prior to this commit, test
```
make -C deps/rabbitmq_web_mqtt ct-proxy_protocol t=http_tests:proxy_protocol
```

was failing with reason
```
exception error: no function clause matching
                 rabbit_net:sockname({rabbit_proxy_socket,#Port<0.96>,
```
2022-08-25 20:00:49 +02:00
David Ansari 28db862d56 Avoid crash when client disconnects before server handles MQTT CONNECT
In case of a resource alarm, the server accepts incoming TCP
connections, but does not read from the socket.
When a client connects during a resource alarm, the MQTT CONNECT frame
is therefore not processed.

While the resource alarm is ongoing, the client might time out waiting
on a CONNACK MQTT packet.

When the resource alarm clears on the server, the MQTT CONNECT frame
gets processed.

Prior to this commit, this results in the following crash on the server:
```
** Reason for termination ==
** {{badmatch,{error,einval}},
    [{rabbit_mqtt_processor,process_login,4,
                            [{file,"rabbit_mqtt_processor.erl"},{line,585}]},
     {rabbit_mqtt_processor,process_request,3,
                            [{file,"rabbit_mqtt_processor.erl"},{line,143}]},
     {rabbit_mqtt_processor,process_frame,2,
                            [{file,"rabbit_mqtt_processor.erl"},{line,69}]},
     {rabbit_mqtt_reader,process_received_bytes,2,
                         [{file,"src/rabbit_mqtt_reader.erl"},{line,307}]},
```

After this commit, the server just logs:
```
[error] <0.887.0> MQTT protocol error on connection 127.0.0.1:55725 -> 127.0.0.1:1883: peername_not_known
```

In case the client already disconnected, we want the server to bail out
early, i.e. not authenticating and registering the client at all
since that can be expensive when many clients connected while the
resource alarm was ongoing.

To detect whether the client disconnected, we rely on inet:peername/1
which will return an error when the peer is not connected anymore.

Ideally we could use some better mechanism for detecting whether the
client disconnected.

The MQTT reader does receive a {tcp_closed, Socket} message once the
socket becomes active. However, we don't really want to read frames
ahead (i.e. ahead of the received CONNECT frame), one reason being that:
"Clients are allowed to send further Control Packets immediately
after sending a CONNECT Packet; Clients need not wait for a CONNACK Packet
to arrive from the Server."

Setting socket option `show_econnreset` does not help either because the client
closes the connection normally.

Co-authored-by: Péter Gömöri @gomoripeti
2022-08-25 18:42:37 +02:00
Jean-Sébastien Pédron 6e9ee4d0da
Remove test code which depended on the `quorum_queue` feature flags
These checks are now irrelevant as the feature flag is required.
2022-08-01 12:41:30 +02:00
Michael Klishin 7c47d0925a
Revert "Correct a double quote introduced in #4603"
This reverts commit 6a44e0e2ef.

That wiped a lot of files unintentionally
2022-04-20 16:05:56 +04:00
Michael Klishin 6a44e0e2ef
Correct a double quote introduced in #4603 2022-04-20 16:01:29 +04:00
Michael Klishin 0ae3f19698
mqtt.queue_type => mqtt.durable_queue_type 2022-03-31 19:48:00 +04:00
Gabriele Santomaggio 2c49748c70
Add quorum queues support for MQTT
Enable the quorum queue for MQTT only if CleanSession is False.
QQs don't support auto-delete flag so in case Clean session is True
the queue will be a classic queue.

Add another group test non_parallel_tests_quorum.
For Mixed test the quorum_queue feature flag must be enabled.

Add log message
2022-03-30 08:49:17 -07:00
Michael Klishin c38a3d697d
Bump (c) year 2022-03-21 01:21:56 +04:00
Michael Klishin f7d32d69f8 Introduce a new CLI tool (scope), rabbitmq-tanzu
For Tanzu (commercial) plugins to attach their commands to instead of
polluting rabbitmqctl.

Pair: @pjk25
(cherry picked from commit 6e0f2436fa)
2021-11-30 14:54:09 +00:00
Alexey Lebedeff e0723d5e66 Prevent crash logs when mqtt user is missing permissions
Fixes #2941

This adds proper exception handlers in the right places. And tests
ensure that it indeed provides nice neat logs without large
stacktraces for every amqp operation.

Unnecessary checking for subscribe permissions on topic was dropped,
as `queue.bind` does exactly the same check. Topic permissions tests
were also added, and they indeed confirm that there was no change in
behaviour.

Ideally the same explicit topic permission check should be dropped for
publishing, but it's more complicated - so for now there only a
detailed comment in the source code explaining it.

A few other things were also optimized away:
- Using amqp client to test for queue existence
- Creating queues/starting consumptions too eagerly, even if not yet
  requested by client
2021-11-12 18:03:05 +01:00
Carl Hörberg 681cb78b0d Test that proxy dest address is picked up in all plugins 2021-03-31 11:28:40 +02:00
Michael Klishin 52479099ec
Bump (c) year 2021-01-22 09:00:14 +03:00
Michael Klishin e8fccbaf48
MQTT auth_SUITE: synchronise concurrent setup with the test 2021-01-13 16:41:03 +03:00
kjnilsson 04a55e0ee6 bug fixes 2020-12-22 15:16:17 +00:00
kjnilsson 067a42e066 Optimise MQTT state machine
It was particularly slow when processing down commands.
2020-12-21 15:58:32 +00:00
kjnilsson 6fdb7d29ec Handle errors in crashing_queues_SUITE
As the connection may crash during the previous declaration and a caught
error would be returned in amqp_connection:open_channel/1 that wasn't
handled previously. Exactly how things fail in this test is most likely
very timing dependent and may vary.

Also fixes mqtt test where the process that set up a mock auth ETS table
was transient when an rpc timeout was introduced
2020-12-03 13:56:09 +00:00
dcorbacho d80e8e1bec Add protocol to auth attempt metrics 2020-09-23 11:16:13 +01:00
dcorbacho b138241b52 Add auth attempt metrics 2020-08-28 13:19:05 +01:00
D Corbacho 1a9632576d Merge pull request #236 from rabbitmq/switch-to-MPL-2.0
Switch to Mozilla Public License 2.0 (MPL 2.0)
2020-07-13 17:40:24 +01:00
dcorbacho 119eb99e8d Switch to Mozilla Public License 2.0 (MPL 2.0) 2020-07-13 17:39:36 +01:00
kjnilsson 3cf84a19b2 Fix mqtt_machine crash bug
When a client performs repeated requests the state machine would crash
with a match exception.

Add unit test suite for mqtt_machine.
2020-07-09 14:41:00 +01:00
Jean-Sébastien Pédron dcc5f7b553 Update copyright (year 2020) 2020-03-10 16:39:48 +01:00
kjnilsson eadf5f7094 Make interactions with Ra async
To avoid blocking when registering or unregistering a client id. This is
ok as informing the current connection holder of the client id is
already async. This should be more scalable and provide much better MQTT
connection setup latency.
2020-02-10 17:28:18 +00:00
Michael Klishin 2927f473ce (c) bump 2019-12-29 05:50:32 +03:00
Michael Klishin cf9e258d49 Make it possible to override client ID in some tests 2019-11-25 17:37:50 +03:00
Michael Klishin 5947ac6961 Use a topic name that has R and W permissions 2019-11-05 17:07:55 +00:00
Michael Klishin 35a99a24a2 Downgrade QoS 2 to QoS 1 when sending Last Will
Closes #214.
2019-11-05 16:54:20 +00:00
Michael Klishin ab1b923794 (c) year 2019-10-22 13:31:13 +03:00
Arnaud Cogoluègnes 26a17e8530 Modernize Java test suite
Migrate to JUnit 5, use TestInfo to create test-related MQTT
client ID when possible, remove Awaitility in favor of a in-house
utility and the use of lambdas, clean some code.
2019-09-23 14:43:40 +02:00
Luke Bakken e8c9b6d118 Remove two unnecessary class variables 2019-09-20 15:51:39 -07:00
Luke Bakken a07c231891 Ensure each test has a meaningful client id 2019-09-20 15:44:28 -07:00
Luke Bakken 2141339a80 Remove another snowflake topic 2019-09-20 09:16:04 -07:00
Luke Bakken 13f881e6e3 Remove another snowflake topic 2019-09-20 05:22:16 -07:00
Luke Bakken e19deefc14 Remove "mid" topic and replace with test-topic 2019-09-20 05:01:29 -07:00
Luke Bakken 60ac7affa5 Use per-testcase instance of TestMqttConnectOptions 2019-09-19 17:12:55 -07:00
Luke Bakken 54a3ab1666 Formatting 2019-09-19 16:37:05 -07:00
Luke Bakken a487dc427a Fix willIsRetained test 2019-09-19 11:39:48 -07:00
Luke Bakken d92c60e882 Fixed the lastWillNotSentOnRestrictedTopic test 2019-09-19 11:17:13 -07:00
Luke Bakken d8669f7bc0 Increase debug level
One test fixed at least
2019-09-19 10:00:43 -07:00
Michael Klishin b94ceeb398 Java integration suite: reduce use of shared mutable state
Per discussion with @acogoluegnes.
2019-09-19 15:26:21 +03:00
Michael Klishin 4755325f19 An attempt to avoid Paho Java state exceptions 2019-09-19 11:39:58 +03:00
Michael Klishin 82f526baed New Paho version does not handle null passwords 2019-09-19 10:28:39 +03:00
Michael Klishin 103dc2c5eb Bump RabbitMQ and Paho clients used in tests 2019-09-19 09:26:26 +03:00
Luke Bakken 92f1ca1971 Rename sparkplug_b to sparkplug 2019-09-06 08:58:04 -07:00
Arnaud Cogoluègnes f0ef67e2fc Use AMQP topic name in translation test
References #206
2019-09-06 15:07:29 +02:00
Luke Bakken 061651f31e Correctly set topic permissions for sparkplug B prefix, and use correct topics in test 2019-09-04 10:24:47 -07:00
Luke Bakken e7554def0a Topic translation CT tests pass 2019-09-04 07:43:35 -07:00
Luke Bakken 8e1ddac03d Add CT tests for topic translation funs, failing currently 2019-09-04 07:43:35 -07:00
Luke Bakken 04fcd898ca Add failing test involving MQTT/Sparkplug B and AMQP interop 2019-09-04 07:43:35 -07:00
Luke Bakken e0504e7617 Add failing test for mqtt.sparkplug_b schema element 2019-09-04 07:43:35 -07:00
Arnaud Cogoluègnes c403200bad Do not reach out to all nodes when listing connections
The way connections are listed already contains all the connections, so
there is no need to reach out to all cluster nodes and aggregate the
results, as it results in duplicate lines.

The command test now uses a cluster to make sure connections are listed
properly in a cluster.

[#167639960]

Fixes #202
2019-08-01 09:29:16 +02:00
Michael Klishin 7d8d7c491c Return false here as this module does not provide an update_state/2 2019-07-02 16:27:10 +02:00
Arnaud Cogoluègnes 689a557c4c Add state_can_expire/0 to mock authn/authz backend
References rabbitmq/rabbitmq-auth-backend-oauth2#28
2019-07-02 15:50:12 +02:00
Jean-Sébastien Pédron 437bb5da96 Java testsuite: Use a third RabbitMQ node for the cluster-wide client ID tracking test
This is to ensure that the test can pass in a mixed-versions cluster
where odd-numbered nodes might not support clsuter-wide client ID
tracking (RabbitMQ 3.7.x).
2019-06-12 16:29:38 +02:00
Jean-Sébastien Pédron cf082aa6fd test/java_SUITE_data/pom.xml: Make it compatible with Java 12 2019-06-12 16:29:06 +02:00
Jean-Sébastien Pédron 3c111a18be mqtt_node: Skip incompatible nodes when configuring Ra cluster
In the cluster_SUITE testsuite:

All even-numbered nodes will use the same code base when using a
secondary Umbrella. Odd-numbered nodes might use an incompatible code
base. When cluster-wide client ID tracking was introduced, it was not
put behind a feature flag because there was no need for one. Here, we
don't have a way to ensure that all nodes participate in client ID
tracking. However, those using the same code should. That's why we
limit our RPC calls to those nodes.

That's also the reason why we use a 5-node cluster: with node 2 and
4 which might not participate, it leaves nodes 1, 3 and 5: thus 3
nodes, the minimum to use Ra in proper conditions.

References #91, #195.
[#135330629]
2019-06-11 18:26:27 +02:00
Jean-Sébastien Pédron 391c44c665 rabbit_auth_backend_mqtt_mock: Move this test module to `test/` 2019-06-11 16:15:10 +02:00
Jean-Sébastien Pédron 8de6ab7e81 cluster_SUITE: Bump suite timestrap to 5 minutes
One minute seems too short for those tests in CI.
2019-06-11 13:52:05 +02:00
Michael Klishin e900354db5 Merge pull request #195 from rabbitmq/rabbitmq-mqtt-91
Cluster-wide MQTT client id tracking
2019-06-11 01:32:20 +03:00
Michael Klishin 91d3d72bf8 Refactor 2019-06-11 01:31:44 +03:00
Michael Klishin 91a6252cff More tests 2019-06-11 01:26:07 +03:00
Arnaud Cogoluègnes 7f8708bd85 Add test to check client id propagation
This commit adds a test to check the MQTT client is properly propagated
to the authentication and authorization backends.

References rabbitmq/rabbitmq-server#1767
2019-06-06 10:46:31 +02:00
Diana Corbacho 7bfe632cb6 Cluster-wide MQTT client id tracking
Uses a ra cluster to keep the client id tracking information - in
the state of the ra machine.

If nodes are decommissioned from the RMQ cluster, the command
decommission_mqtt_node must be invoked first to disconnect the clients
on that node and remove the node from the ra cluster.

[#135330629]
2019-05-16 17:50:06 +01:00
Spring Operator 96006cd58b URL Cleanup
This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener).

# Fixed URLs

## Fixed Success
These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended.

* [ ] http://www.apache.org/licenses/LICENSE-2.0 with 1 occurrences migrated to:
  https://www.apache.org/licenses/LICENSE-2.0 ([https](https://www.apache.org/licenses/LICENSE-2.0) result 200).
2019-03-21 03:17:58 -05:00
Spring Operator 852c61ea99 URL Cleanup
This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener).

# HTTP URLs that Could Not Be Fixed
These URLs were unable to be fixed. Please review them to see if they can be manually resolved.

* http://blog.listincomprehension.com/search/label/procket (200) with 1 occurrences could not be migrated:
   ([https](https://blog.listincomprehension.com/search/label/procket) result ClosedChannelException).
* http://dozzie.jarowit.net/trac/wiki/TOML (200) with 1 occurrences could not be migrated:
   ([https](https://dozzie.jarowit.net/trac/wiki/TOML) result SSLHandshakeException).
* http://dozzie.jarowit.net/trac/wiki/subproc (200) with 1 occurrences could not be migrated:
   ([https](https://dozzie.jarowit.net/trac/wiki/subproc) result SSLHandshakeException).
* http://e2project.org (200) with 1 occurrences could not be migrated:
   ([https](https://e2project.org) result AnnotatedConnectException).
* http://nitrogenproject.com/ (200) with 2 occurrences could not be migrated:
   ([https](https://nitrogenproject.com/) result ConnectTimeoutException).
* http://proper.softlab.ntua.gr (200) with 1 occurrences could not be migrated:
   ([https](https://proper.softlab.ntua.gr) result SSLHandshakeException).
* http://yaws.hyber.org (200) with 1 occurrences could not be migrated:
   ([https](https://yaws.hyber.org) result AnnotatedConnectException).
* http://choven.ca (503) with 1 occurrences could not be migrated:
   ([https](https://choven.ca) result ConnectTimeoutException).

# Fixed URLs

## Fixed But Review Recommended
These URLs were fixed, but the https status was not OK. However, the https status was the same as the http request or http redirected to an https URL, so they were migrated. Your review is recommended.

* http://fixprotocol.org/ (301) with 1 occurrences migrated to:
  https://fixtrading.org ([https](https://fixprotocol.org/) result SSLHandshakeException).
* http://erldb.org (UnknownHostException) with 1 occurrences migrated to:
  https://erldb.org ([https](https://erldb.org) result UnknownHostException).

## Fixed Success
These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended.

* http://cloudi.org/ with 27 occurrences migrated to:
  https://cloudi.org/ ([https](https://cloudi.org/) result 200).
* http://erlware.org/ with 1 occurrences migrated to:
  https://erlware.org/ ([https](https://erlware.org/) result 200).
* http://inaka.github.io/cowboy-trails/ with 1 occurrences migrated to:
  https://inaka.github.io/cowboy-trails/ ([https](https://inaka.github.io/cowboy-trails/) result 200).
* http://ninenines.eu with 6 occurrences migrated to:
  https://ninenines.eu ([https](https://ninenines.eu) result 200).
* http://www.actordb.com/ with 2 occurrences migrated to:
  https://www.actordb.com/ ([https](https://www.actordb.com/) result 200).
* http://www.cs.kent.ac.uk/projects/wrangler/Home.html with 1 occurrences migrated to:
  https://www.cs.kent.ac.uk/projects/wrangler/Home.html ([https](https://www.cs.kent.ac.uk/projects/wrangler/Home.html) result 200).
* http://www.rabbitmq.com/mpl.html with 1 occurrences migrated to:
  https://www.rabbitmq.com/mpl.html ([https](https://www.rabbitmq.com/mpl.html) result 200).
* http://www.rabbitmq.com/mqtt.html with 1 occurrences migrated to:
  https://www.rabbitmq.com/mqtt.html ([https](https://www.rabbitmq.com/mqtt.html) result 200).
* http://www.rebar3.org with 1 occurrences migrated to:
  https://www.rebar3.org ([https](https://www.rebar3.org) result 200).
* http://contributor-covenant.org with 1 occurrences migrated to:
  https://contributor-covenant.org ([https](https://contributor-covenant.org) result 301).
* http://contributor-covenant.org/version/1/3/0/ with 1 occurrences migrated to:
  https://contributor-covenant.org/version/1/3/0/ ([https](https://contributor-covenant.org/version/1/3/0/) result 301).
* http://inaka.github.com/apns4erl with 1 occurrences migrated to:
  https://inaka.github.com/apns4erl ([https](https://inaka.github.com/apns4erl) result 301).
* http://inaka.github.com/edis/ with 1 occurrences migrated to:
  https://inaka.github.com/edis/ ([https](https://inaka.github.com/edis/) result 301).
* http://lasp-lang.org/ with 1 occurrences migrated to:
  https://lasp-lang.org/ ([https](https://lasp-lang.org/) result 301).
* http://saleyn.github.com/erlexec with 1 occurrences migrated to:
  https://saleyn.github.com/erlexec ([https](https://saleyn.github.com/erlexec) result 301).
* http://www.mozilla.org/MPL/ with 27 occurrences migrated to:
  https://www.mozilla.org/MPL/ ([https](https://www.mozilla.org/MPL/) result 301).
* http://www.rabbitmq.com/man/rabbitmq-plugins.1.man.html with 1 occurrences migrated to:
  https://www.rabbitmq.com/man/rabbitmq-plugins.1.man.html ([https](https://www.rabbitmq.com/man/rabbitmq-plugins.1.man.html) result 301).
* http://zhongwencool.github.io/observer_cli with 1 occurrences migrated to:
  https://zhongwencool.github.io/observer_cli ([https](https://zhongwencool.github.io/observer_cli) result 301).
2019-03-20 03:18:59 -05:00
Spring Operator c90ca44234 URL Cleanup
This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener).

# Fixed URLs

## Fixed Success
These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended.

* http://maven.apache.org/xsd/maven-4.0.0.xsd with 1 occurrences migrated to:
  https://maven.apache.org/xsd/maven-4.0.0.xsd ([https](https://maven.apache.org/xsd/maven-4.0.0.xsd) result 200).

# Ignored
These URLs were intentionally ignored.

* http://maven.apache.org/POM/4.0.0 with 2 occurrences
* http://www.w3.org/2001/XMLSchema-instance with 1 occurrences
2019-03-19 20:10:10 -05:00
Spring Operator 7e218211b8 URL Cleanup
This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener).

# Fixed URLs

## Fixed Success
These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended.

* http://www.apache.org/licenses/LICENSE-2.0 migrated to:
  https://www.apache.org/licenses/LICENSE-2.0 ([https](https://www.apache.org/licenses/LICENSE-2.0) result 200).
* http://www.rabbitmq.com migrated to:
  https://www.rabbitmq.com ([https](https://www.rabbitmq.com) result 200).

# Ignored
These URLs were intentionally ignored.

* http://maven.apache.org/POM/4.0.0
* http://maven.apache.org/xsd/maven-4.0.0.xsd
* http://www.w3.org/2001/XMLSchema-instance
2019-03-11 21:54:05 -05:00
Michael Klishin 48bac2500a Formatting 2019-02-03 20:09:41 +03:00
Michael Klishin 9caf40afa1 Cosmetics 2019-02-03 19:43:44 +03:00
Ryan Sandbach 08f97b9e6f New tests for retainer translation. 2019-02-01 00:21:10 -05:00
Arnaud Cogoluègnes ec65574e1f Add client ID to connection metadata
[#153246723]

Fixes #152
2019-01-22 10:30:25 +01:00
Michael Klishin 16d262f908 Additional tests extracted from rabbitmq/rabbitmq-stomp#130
The settings are already supported by this plugin.
2019-01-02 20:36:51 +03:00
Arnaud Cogoluègnes f1c1dbf30d Use Maven wrapper for Java test suite
This avoids depending on a local Maven.
2018-11-06 11:46:12 +01:00
Arnaud Cogoluègnes 9043d97f60 Fix Maven tests for CI environment
OpenJDK 1.8.0_181 on Debian-based distros introduces a bug that breaks
the Maven Surefire plugin (test plugin). This commit adds an argument to
the plugin configuration to fix this problem. It also bumps some Java
dependencies.
2018-11-06 11:31:18 +01:00
Jean-Sébastien Pédron 665abcdf2c Merge branch 'read-cert-name-from-cert-part2' 2017-12-15 12:06:13 +01:00
Jean-Sébastien Pédron be27eea7ac java_SUITE_data: Ignore target/ 2017-12-15 12:05:24 +01:00
Jean-Sébastien Pédron 2993a1426b java_SUITE: Get certificate name from the certificate itself
... instead of hard-coding the value. This fixes the testsuite when the
generated certificate configuration changes.

The same change was made to auth_SUITE in commit a11e96caa0.

[#153697697]
2017-12-15 12:02:36 +01:00
Jean-Sébastien Pédron ac32092fc2 Merge branch 'read-cert-name-from-cert' 2017-12-15 11:27:29 +01:00
Jean-Sébastien Pédron a11e96caa0 auth_SUITE: Get certificate name from the certificate itself
... instead of hard-coding the value. This fixes the testsuite when the
generated certificate configuration changes.

[#153697697]
2017-12-15 11:22:01 +01:00
Luke Bakken 60dfb72800 Fix tests broken by rabbitmq/rabbitmq_ct_helpers#17 2017-12-07 15:36:14 -08:00
Jean-Sébastien Pédron d3aaea7244 reader_SUITE: Increase timer in expect_publish() to 5 seconds
This reduces the risk of test failures.

(cherry picked from commit 50e842a200a482a67de6eaf67ab66774f63b48a1)
2017-08-11 14:39:00 +02:00
Jean-Sébastien Pédron 8a0d88cf1b reader_SUITE: Increase timer in expect_publish() to 5 seconds
This reduces the risk of test failures.
2017-08-11 12:27:40 +02:00
Michael Klishin 885daa1d6d Merge branch 'master' into rabbitmq-server-1229 2017-06-13 23:56:49 +03:00
Michael Klishin 3fda50bccd Make this test more robust
* Handle duplicate keys (see 82d1cb23e9, for instance)
 * Use maps since this test is in master only
 * Use eunit assertions that would print arguments on failures
2017-06-11 01:42:17 +03:00
Arnaud Cogoluègnes 81ab03c133 Add client_id as an topic authz expandable variable
References rabbitmq/rabbitmq-server#1229
2017-06-07 14:41:59 +02:00
Michael Klishin a1b46471fd Merge branch 'stable' 2017-04-02 22:02:20 +03:00
Michael Klishin fff8f52901 (c) year 2017-04-02 21:48:53 +03:00
Daniil Fedotov 897e194dc8 Config schema test for plugin
Part of [#141481501]
Moved from rabbitmq-server
2017-03-17 11:01:51 +00:00
Jean-Sébastien Pédron 96b51d2bc7 Merge branch 'stable' 2017-03-08 10:06:14 +01:00
Jean-Sébastien Pédron 034ac28159 reader_SUITE: Match the new `connection_coarse_metrics` field
The tuple returned by a read of `connection_coarse_metrics` contains a
new counter at the end. We ignore it but the pattern matching must be
updated.

Before this, the testcase failed with the following error:

    reader_SUITE:stats failed on line 147
    Reason: {badmatch,[{<19064.547.0>,70,30,5578,0}]}
2017-03-08 09:22:57 +01:00
Arnaud Cogoluègnes 2fd3da301b Merge branch 'stable' 2017-02-27 14:04:16 +01:00
Arnaud Cogoluègnes 9bb903010c Remove unused imports in Java test suite 2017-02-27 14:03:51 +01:00
Arnaud Cogoluègnes 45046566f5 Merge branch 'stable'
Conflicts:
	test/java_SUITE_data/src/test/java/com/rabbitmq/mqtt/test/MqttTest.java
2017-02-27 14:03:21 +01:00
Arnaud Cogoluègnes 2c2c24d18f Fix Java test build and test on Java 9
Need to use a recent version of Groovy in the Maven Groovy plugin.
Avoid using CGLIB-based features of Awaitility, as they don't work
on Java 9 (Awaitility is on its way to use Byte Buddy instead of CGLIB,
but no stable release yet).
2017-02-27 11:53:33 +01:00
Michael Klishin f383a3c023 Drive by change: squash a warning 2017-02-23 20:33:42 +03:00
Arnaud Cogoluègnes fba3782869 Check topic access when sending last will
The check is actually already done at the AMQP level, but this commit
adds an "upstream" check, a more specific warning message, and a test.

Fixes #114
2017-02-21 16:13:07 +01:00
Arnaud Cogoluègnes 61f38005df Polish proxy protocol test suite
Add call to rabbit_ct_helpers:testcase_started.

References rabbitmq/rabbitmq-server#589
2017-02-13 10:42:04 +01:00
Arnaud Cogoluègnes 1bc5c7afd2 Add support for proxy protocol
References rabbitmq/rabbitmq-server#589
2017-02-07 17:22:14 +01:00
Arnaud Cogoluègnes e0db62f69c Merge branch 'master' into rabbitmq-server-1085 2017-01-31 17:38:53 +01:00
Diana Corbacho c116f23d90 Merge branch 'stable' 2017-01-27 07:29:16 +00:00
Michael Klishin 4e55c07d1a Wording 2017-01-26 23:19:42 +03:00
Diana Corbacho 53e1d8e776 Notify recv_oct, send_oct, reductions and garbage_collection in core metrics 2017-01-26 16:15:08 +00:00
Michael Klishin b99d77d16f Merge branch 'stable' 2017-01-25 22:23:25 +03:00
Michael Klishin c70a8d3a97 Don't assume stats tables are empty
We don't need them to be; what we care about is that
in this particular test, no new entries are inserted.
2017-01-25 22:15:39 +03:00
Diana Corbacho 12f91458f0 Add test for handling invalid frames 2017-01-25 16:21:59 +00:00
Arnaud Cogoluègnes 96aaf35900 Add topic authorisation for consumption
Part of rabbitmq/rabbitmq-server#1085
2017-01-23 12:10:23 +01:00
Arnaud Cogoluègnes 85636953a4 Use check_topic_access on publishing
check_resource_access used to be called with
the MQTT topic as resource name and kind = topic.
It makes more sense now to call check_topic_access
with the exchange as resource name, kind = topic,
and routing key in the context.

References rabbitmq/rabbitmq-server#505
2016-12-29 16:34:19 +01:00
Michael Klishin 500b66087a Merge branch 'stable' 2016-12-20 01:39:05 +03:00
Michael Klishin 6d94828a8d Revert "Give global policies more time to propagate"
This reverts commit 4e3849b0c3.
2016-12-20 01:35:41 +03:00
Michael Klishin 8a23720840 Merge branch 'stable' 2016-12-20 01:17:45 +03:00
Michael Klishin 4e3849b0c3 Give global policies more time to propagate
Sigh, CI.
2016-12-20 01:13:01 +03:00
Michael Klishin cfcde1d143 Merge branch 'stable' 2016-12-20 00:50:04 +03:00
Arnaud Cogoluègnes 87628f9f51 Use binary for port-to-vhost mapping key
Behaves better as a JSON document key than an integer.

Fixes #111
2016-12-19 17:36:18 +01:00
Arnaud Cogoluègnes b8344cdc27 Map client connection vhost to a port
Fixes #111
2016-12-19 15:00:43 +01:00
Arnaud Cogoluègnes d1c2474a89 Merge branch 'stable' 2016-12-16 10:59:10 +01:00
Michael Klishin 2d3c004efb Merge branch 'stable' into rabbitmq-mqtt-73 2016-12-15 17:46:24 +03:00
Arnaud Cogoluègnes 8749233066 Merge branch 'stable' 2016-12-15 15:42:36 +01:00
Arnaud Cogoluègnes 7424551de0 Fix race condition in test 2016-12-15 15:38:42 +01:00
Arnaud Cogoluègnes 6d53781e64 Merge branch 'stable' 2016-12-15 14:23:55 +01:00
Arnaud Cogoluègnes 335997d140 Use clean sessions in last will retained test 2016-12-15 14:23:23 +01:00
Arnaud Cogoluègnes e37b8135b1 Merge branch 'stable'
Conflicts:
	test/java_SUITE_data/src/test/java/com/rabbitmq/mqtt/test/MqttTest.java
2016-12-15 12:50:16 +01:00
Arnaud Cogoluègnes 20d35a1482 Use awaitility for Java tests 2016-12-15 12:46:14 +01:00
Arnaud Cogoluègnes 2a9a6cb261 Add test case for cert user/vhost mapping
Fixes #73
2016-12-13 17:31:34 +01:00
Arnaud Cogoluègnes 7e03af30fd Introduce mqtt_default_vhosts global parameter
Fixes #73
2016-12-13 14:46:15 +01:00
Arnaud Cogoluègnes d424894dc6 Test connection fails when vhost not allowed for cert user 2016-12-12 10:17:29 +01:00
Arnaud Cogoluègnes 8f9e8489c2 Optionally map user certificate to virtual host
Use a global runtime parameter to map the DN of the certificate
to a virtual host.

Fixes #73
2016-12-09 16:48:47 +01:00
Jean-Sébastien Pédron b87baed8bb Do not use -include_lib() with own headers
This fixes the build outside of an Umbrella-like setup, ie. when
dependencies of this plugin are put into the `deps` subdirectory.
2016-12-08 18:07:13 +01:00
Jean-Sébastien Pédron 8216cb12f1 Merge branch 'stable' 2016-12-07 15:48:04 +01:00
Michael Klishin b3f2bcfaed Merge branch 'stable' into rabbitmq-mqtt-100 2016-12-06 18:54:29 +03:00
Arnaud Cogoluègnes b1627afe81 Gracefully close connections to non-existent virtual hosts
Return CONNACK 4 code when the virtual host doesn't exist.
The MQTT description for this return code states "The data in
the user name or password is malformed", which not exactly
accurate but better than a pending or abruptly closed connection.
The server logs also a more meaningful message.

Fixes #100
2016-12-06 16:09:50 +01:00
Michael Klishin dca3081a5d Merge pull request #107 from rabbitmq/rabbitmq-cli-121
A CLI command to list mqtt connections
2016-12-06 18:07:25 +03:00
Michael Klishin 4a6a231484 Cosmetics 2016-12-06 18:06:44 +03:00
Michael Klishin a077b95f86 Merge branch 'stable' 2016-12-06 17:56:21 +03:00
Daniil Fedotov f411a74e10 Test list_mqtt_connections command 2016-12-06 14:24:45 +00:00
Arnaud Cogoluègnes 388d949645 Support Erlang string vhosts in retainer supervisor
Fixes #86
2016-12-06 11:03:02 +01:00
Michael Klishin bc8e2541bd Merge branch 'stable' 2016-12-05 14:27:40 +03:00
Arnaud Cogoluègnes a7a0174a41 Retain last will message
Fixes #74
2016-12-05 11:05:30 +01:00
Daniil Fedotov 7cd6fdec7e Merge branch 'stable' 2016-09-28 11:39:54 +01:00
Daniil Fedotov c610ca1c0e Do not log java test output 2016-09-28 11:39:44 +01:00
Arnaud Cogoluègnes e0aac5b183 Merge branch 'stable' 2016-09-27 15:34:09 +02:00
Arnaud Cogoluègnes 46d0977209 Use quiet mode for Maven 2016-09-27 15:33:31 +02:00
Arnaud Cogoluègnes 7f43ea05d8 Merge branch 'stable' 2016-09-27 13:56:16 +02:00
Arnaud Cogoluègnes 2d442353ee Refactor Java tests
Use JUnit4-style tests, increase max-in-flight messages to make
tests more resilient, synchronize test variables.
2016-09-27 13:32:40 +02:00
Arnaud Cogoluègnes c076259000 Specify file format for client certificate
Use PKCS12 to load the KeyStore object, not JKS. Java 8
manages to load the certificate anyway, but not Java 6, nor Java  7.
2016-09-27 10:30:44 +02:00
Daniil Fedotov 9eab2c7704 Report java test result in test log 2016-09-26 13:45:05 +01:00
Daniil Fedotov abe00f3d1a Cleanup comments 2016-09-23 18:06:05 +01:00
Daniil Fedotov 507ef875ea test dir cleanup 2016-09-23 17:19:03 +01:00
Daniil Fedotov 493805fd95 Run tests via maven 2016-09-23 16:42:21 +01:00
Michael Klishin c510fef54a Merge branch 'stable' 2016-09-02 02:07:46 +03:00
Michael Klishin d318ca2fa3 Rename 2016-09-02 01:54:57 +03:00
Michael Klishin ee213084f8 Wording, naming 2016-09-02 01:33:34 +03:00
Daniil Fedotov e8ca3ac8ff test comments 2016-09-01 17:21:02 +01:00
Daniil Fedotov 4b688b9e63 Make MQTT authentication correspond with docs. Added tests 2016-09-01 16:54:51 +01:00
Daniil Fedotov e348357392 Test empty password login 2016-09-01 10:43:14 +01:00
Jean-Sébastien Pédron 59523f1832 java_SUITE: Fetch dependencies using Maven
Thus, we do not use to clone and build org.eclipse.paho.client.mqttv3,
nor we depend on a local clone of rabbitmq-java-client.

While here, move all java_SUITE-specific files to `java_SUITE_data`.
2016-08-31 13:54:28 +02:00
Jean-Sébastien Pédron 08c29be1cf java_SUITE: Fetch dependencies using Maven
Thus, we do not use to clone and build org.eclipse.paho.client.mqttv3,
nor we depend on a local clone of rabbitmq-java-client.

While here, move all java_SUITE-specific files to `java_SUITE_data`.
2016-08-31 10:15:21 +02:00
Michael Klishin 969f3e966f Merge branch 'stable' 2016-07-12 08:25:40 -07:00
kjnilsson b76cfbe5dc Move to common test
travis config
2016-07-12 12:46:11 +01:00
Michael Klishin 6c16d80527 Merge branch 'stable' 2016-04-25 08:31:30 -07:00
Michael Klishin 2c8eec7dc1 Update Paho Java git repo location 2016-04-25 08:22:13 -07:00
Daniil Fedotov 5c98b84a56 Merge branch 'stable' 2016-04-22 13:32:57 +01:00
Daniil Fedotov 2d2b8f96d8 Tests message redelivery when resuming session 2016-04-22 12:25:30 +01:00
Michael Klishin a72c9e14d2 Merge branch 'stable' 2016-03-05 11:27:29 +03:00
Michael Klishin 44389f778b In fact, even more 2016-03-05 11:21:00 +03:00
Michael Klishin 72bfeef88b Wait a bit more 2016-03-05 11:20:54 +03:00
Michael Klishin 9b7c29841b Cosmetics 2016-03-05 11:09:38 +03:00
Michael Klishin 706d82dafb Explain 2016-03-05 11:09:26 +03:00
Michael Klishin 4c5aecf0f0 skip_publishes => expect_publishes 2016-03-05 11:04:56 +03:00
Michael Klishin 1078f5787f Trailing ws 2016-03-05 11:01:20 +03:00
Daniil Fedotov 98cf125e39 Defer last receive after blocking 2016-03-04 20:33:01 +00:00
Michael Klishin c619f638ee Merge branch 'stable' 2016-03-03 14:38:16 +03:00
Daniil Fedotov 6b5de44f9c Tests for mqtt blocking 2016-03-02 16:57:48 +00:00
Daniil Fedotov d1685b08fd More tests to check QoS2 is not ignored 2016-01-27 12:05:08 +00:00
Daniil Fedotov 64f5911ec2 Downgrade publishes if QoS = 2 to QoS = 1 2016-01-12 18:02:37 +00:00
Michael Klishin 9ba1da7434 Update (c) info 2016-01-01 12:59:18 +03:00
Michael Klishin 51e887e52e Update test expectation 2015-12-18 16:32:26 +03:00
Michael Klishin 624a7741cf Merge branch 'colons-in-username' of https://github.com/lshift/rabbitmq-mqtt into lshift-colons-in-username 2015-11-28 20:42:22 +03:00
Loïc Hoguin 597eecdaf8 Remove unneeded TCP options from config in .app.src files 2015-11-26 14:01:42 +01:00
ash 001f4a1a01 add option to ignore colons in usernames 2015-11-19 11:36:24 +00:00
Jean-Sébastien Pédron 3441383d18 make tests: Pass certificates path down to test/Makefile
This allows ant to detect the certificates and enable the SSL tests.
2015-11-05 17:50:58 +01:00
Jean-Sébastien Pédron 9626e1fbe0 Merge branch 'master' into erlang.mk 2015-10-23 12:13:24 +02:00
Michael Klishin c15812ac44 merge stable into master 2015-10-21 20:18:33 +03:00
Jean-Sébastien Pédron e2d80945cf setup-rabbit-test.sh: Take rabbitmqctl location from environment 2015-10-21 14:30:37 +02:00
Jean-Sébastien Pédron 08b5c3a009 test/build.xml: Take Java client location from environment 2015-10-21 14:30:03 +02:00
Jean-Sébastien Pédron 9d5037344d Initial move to erlang.mk 2015-10-19 12:28:46 +02:00
Michael Klishin 1096f3182d Merge branch 'stable' 2015-09-22 12:38:31 +03:00
Michael Klishin 85f9f2df5b Two more warnings 2015-09-22 02:31:15 -07:00
Michael Klishin 3981be3e3d Squash a few warnings in tests 2015-09-22 02:26:22 -07:00
Giuseppe Privitera 340bb5d70b refactored tests to use rabbitmq_mqtt:env/1 2015-09-17 23:27:13 +01:00
Giuseppe Privitera 9039d7398b added .app file with some configuration used by tests 2015-09-17 23:26:05 +01:00
Giuseppe Privitera 1544360485 removed unused test 2015-09-17 23:23:49 +01:00
Giuseppe Privitera 0213ec24e9 use assertEqual instead of pattern matching 2015-09-17 15:40:10 +01:00
Giuseppe Privitera 578ac7169b coerce default_user & default_pass 2015-09-17 14:50:17 +01:00