Drop of messages with History "keep all" but not with "keep last"

Open
#385 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp

Research direction

Start with the MinimalPublisher and MinimalSubscriber snippets in the issue, checking the mismatch between the comments and the KeepLast QoS used in both examples. Reproduce the delayed-subscriber case with 7,000 messages, then determine the applicable Fast RTPS queue limit and verify completion by explaining the retained-message count and the QoS values required.

Written by the indexing model from the issue text.

Description

I am creating a publisher and subscriber with QoS History "Keep all" and Durability "transient local".

If publisher publishes more than 5000 and messages, then I run the subscriber, to start listen, it will only capture last 5k messages and not all messages.

Now if I change the History to "keep last" and depth 50000, and if I do the same thing (starting subscriber after publishing 5000 messages), subscriber listen all the messages.

I want to know what the maximum queue depth allowed in fast rtps which can be adhered.

Publisher code:
#include
#include
#include
#include

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int32.hpp"

using namespace std::chrono_literals;

class MinimalPublisher : public rclcpp::Node
{
public:
MinimalPublisher()
: Node("minimal_publisher"), count_(0)
{
// Set up QoS with history keep all, reliability reliable, and durability transient local
auto qos = rclcpp::QoS(rclcpp::KeepLast(50000))
.reliable()
.transient_local();

    publisher_ = this->create_publisher<std_msgs::msg::Int32>("topic", qos);
    timer_ = this->create_wall_timer(
        200ms, std::bind(&MinimalPublisher::timer_callback, this)); // Changed to 200ms
}

private:
void timer_callback()
{
if (count_ >= 7000) {
rclcpp::shutdown(); // Stop publishing after 7000 messages
return;
}

    auto message = std_msgs::msg::Int32();
    message.data = count_;
    RCLCPP_INFO(this->get_logger(), "Publishing: '%d'", message.data);
    publisher_->publish(message);
    count_++;
}

rclcpp::TimerBase::SharedPtr timer_;
rclcpp::Publisher<std_msgs::msg::Int32>::SharedPtr publisher_;
size_t count_;

};

int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared());
rclcpp::shutdown();
return 0;
}

Subscriber code:
#include

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int32.hpp"
using std::placeholders::_1;

class MinimalSubscriber : public rclcpp::Node
{
public:
MinimalSubscriber()
: Node("minimal_subscriber")
{
// Set up QoS with history keep all, reliability reliable, and durability transient local
auto qos = rclcpp::QoS(rclcpp::KeepLast(50000))
.reliable()
.transient_local();

    subscription_ = this->create_subscription<std_msgs::msg::Int32>(
        "/topic", qos, std::bind(&MinimalSubscriber::topic_callback, this, _1));
}

private:
void topic_callback(const std_msgs::msg::Int32::SharedPtr msg) const
{
RCLCPP_INFO(this->get_logger(), "I heard: '%d'", msg->data);
}

rclcpp::Subscription<std_msgs::msg::Int32>::SharedPtr subscription_;

};

int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared());
rclcpp::shutdown();
return 0;
}

please change the QoS values in code as needed.

Dominant language
C
Stars
121
Forks
89
Avg merge
17h 40m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ros2/rmw

All issues in ros2/rmw

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.