Home > Software design >  Pusher error: The data content of this event exceeds the allowed maximum (10240 bytes)
Pusher error: The data content of this event exceeds the allowed maximum (10240 bytes)

Time:07-28

I'm working on a project where I want to live display users' points whenever the gain or lose points.

I have an api that sends event to the frontend:

    public function test(Request $request){
        $message = $request->message;
        $users = User::all()->where('company_id', $message);
        event(new MyEvent([$users]));
    }

Whenever the api is called, I recieve the following error:

Illuminate\Broadcasting\BroadcastException: Pusher error: The data content of this event exceeds the allowed maximum (10240 bytes).

How can this be solved?

CodePudding user response:

The simple answer is to reduce the payload size - Pusher has a size limit on the body of an event - https://pusher.com/docs/channels/library_auth_reference/rest-api/#post-event-trigger-an-event

They also list some strategies for reducing payload size, such as:

  • sending multiple small events instead one one large event (chunking)

  • using compression to reduce payload size

  • sending a link the client that downloads the content instead of transmitting it via Channels.

See https://support.pusher.com/hc/en-us/articles/4412243423761-What-Is-The-Message-Size-Limit-When-Publishing-an-Event-in-Channels- for more info

CodePudding user response:

Source: https://support.pusher.com/hc/en-us/articles/4412243423761-What-Is-The-Message-Size-Limit-When-Publishing-an-Event-in-Channels-

The message size limit is 10KB.

There are several approaches to work around this limit:

  1. Chunking. One approach is to split your large message into smaller chunks before publishing, then recombine them on receipt. This repository shows an example of a chunking protocol: https://github.com/pusher/pusher-channels-chunking-example.
  2. Linking. Instead of sending a large message via Pusher Channels, you could store that message elsewhere, and just send your clients send a link to that content.
  3. Compression, e.g.
  4. A dedicated cluster. If none of the above are suitable and you really need to sender larger single messages, we can set up a dedicated cluster. If you are interested in provisioning a dedicated cluster as part of an enterprise package please contact Pusher sales.
  • Related