1.. zephyr:code-sample:: zbus-msg-subscriber
2   :name: Message subscriber
3   :relevant-api: zbus_apis
4
5   Use zbus message subscribers to listen to messages published to channels.
6
7Overview
8********
9This sample illustrates how to use a message subscriber in different ways with other types of
10observers. It is possible to explore the pool isolation feature by setting the pool size and if it
11is static or dynamic by setting the proper :kconfig:option:`CONFIG_ZBUS_MSG_SUBSCRIBER_BUF_ALLOC`.
12
13Building and Running
14********************
15
16This project outputs to the console.  It can be built and executed
17on QEMU as follows:
18
19.. zephyr-app-commands::
20   :zephyr-app: samples/subsys/zbus/msg_subscriber
21   :host-os: unix
22   :board: qemu_x86
23   :goals: run
24
25Sample Output
26=============
27
28.. code-block:: console
29
30   -- west build: running target run
31   [0/1] To exit from QEMU enter: 'CTRL+a, x'[QEMU] CPU: qemu32,+nx,+pae
32   Booting from ROM..
33   I: ----> Publishing to acc_data_chan channel
34   I:  AL Memory allocated 28 bytes. Total allocated 28 bytes
35   I: From listener foo_lis -> Acc x=1, y=10, z=100
36   I: From msg subscriber bar_msg_sub1 -> Acc x=1, y=10, z=100
37   I: From msg subscriber bar_msg_sub2 -> Acc x=1, y=10, z=100
38   I: From msg subscriber bar_msg_sub3 -> Acc x=1, y=10, z=100
39   I: From msg subscriber bar_msg_sub4 -> Acc x=1, y=10, z=100
40   I: From msg subscriber bar_msg_sub5 -> Acc x=1, y=10, z=100
41   I: From msg subscriber bar_msg_sub6 -> Acc x=1, y=10, z=100
42   I: From msg subscriber bar_msg_sub7 -> Acc x=1, y=10, z=100
43   I: From msg subscriber bar_msg_sub8 -> Acc x=1, y=10, z=100
44   I: From msg subscriber bar_msg_sub9 -> Acc x=1, y=10, z=100
45   I: From msg subscriber bar_msg_sub10 -> Acc x=1, y=10, z=100
46   I: From msg subscriber bar_msg_sub11 -> Acc x=1, y=10, z=100
47   I: From msg subscriber bar_msg_sub12 -> Acc x=1, y=10, z=100
48   I: From msg subscriber bar_msg_sub13 -> Acc x=1, y=10, z=100
49   I: From msg subscriber bar_msg_sub14 -> Acc x=1, y=10, z=100
50   I: From msg subscriber bar_msg_sub15 -> Acc x=1, y=10, z=100
51   I:  FR Memory freed 28 bytes. Total allocated 0 bytes
52   I: From msg subscriber bar_msg_sub16 -> Acc x=1, y=10, z=100
53   I: From subscriber bar_sub1 -> Acc x=1, y=10, z=100
54   I: From subscriber bar_sub2 -> Acc x=1, y=10, z=100
55   I: ----> Publishing to acc_data_chan channel
56   I:  AL Memory allocated 28 bytes. Total allocated 28 bytes
57   I: From listener foo_lis -> Acc x=2, y=20, z=200
58   I: From msg subscriber bar_msg_sub1 -> Acc x=2, y=20, z=200
59   I: From msg subscriber bar_msg_sub2 -> Acc x=2, y=20, z=200
60   I: From msg subscriber bar_msg_sub3 -> Acc x=2, y=20, z=200
61   I: From msg subscriber bar_msg_sub4 -> Acc x=2, y=20, z=200
62   I: From msg subscriber bar_msg_sub5 -> Acc x=2, y=20, z=200
63   I: From msg subscriber bar_msg_sub6 -> Acc x=2, y=20, z=200
64   I: From msg subscriber bar_msg_sub7 -> Acc x=2, y=20, z=200
65   I: From msg subscriber bar_msg_sub8 -> Acc x=2, y=20, z=200
66   I: From msg subscriber bar_msg_sub9 -> Acc x=2, y=20, z=200
67   I: From msg subscriber bar_msg_sub10 -> Acc x=2, y=20, z=200
68   I: From msg subscriber bar_msg_sub11 -> Acc x=2, y=20, z=200
69   I: From msg subscriber bar_msg_sub12 -> Acc x=2, y=20, z=200
70   I: From msg subscriber bar_msg_sub13 -> Acc x=2, y=20, z=200
71   I: From msg subscriber bar_msg_sub14 -> Acc x=2, y=20, z=200
72   I: From msg subscriber bar_msg_sub15 -> Acc x=2, y=20, z=200
73   I:  FR Memory freed 28 bytes. Total allocated 0 bytes
74   I: From msg subscriber bar_msg_sub16 -> Acc x=2, y=20, z=200
75   I: From subscriber bar_sub1 -> Acc x=2, y=20, z=200
76   I: From subscriber bar_sub2 -> Acc x=2, y=20, z=200
77   <continues>
78
79Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.
80