Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription Data Disorder Problem #690

Open
li1786422 opened this issue Oct 26, 2023 · 10 comments
Open

Subscription Data Disorder Problem #690

li1786422 opened this issue Oct 26, 2023 · 10 comments
Assignees
Labels
defect Suspected defect such as a bug or regression

Comments

@li1786422
Copy link

li1786422 commented Oct 26, 2023

Observed behavior

Please ask js_SubscribeSync(&sub, js, subj, &jsOpts, NULL, NULL); Subscribe to the topic and then pass the
while(1){
natsSubscription_NextMsg(&msg, sub, 5000);
if (s ! = NATS_OK)
sleep(1)//sleep 1 seconds this is pseudocode
s = natsMsg_Ack(msg, nullptr);
The method natsMsg_Destroy(msg);
}
where the configuration information for the stream is :{
jsStreamConfig cfg;
jsStreamConfig_Init(&cfg);
cfg.Name = stream;
// Set the subject
cfg.Subjects = (const char*[1]){subj};
cfg.SubjectsLen = 1;
// Make it a memory stream.
cfg.Storage = js_MemoryStorage;
// Add the stream,
s = js_AddStream(&si, js, &cfg, NULL, NULL);
}
Publish message by{
js_Publish(nullptr,js,subject,data,len,nullptr,nullptr)
}
Continuously print the data, the order of the fetched data is messed up what is the reason why the client pulls the When the client pulls data, how to ensure the data order is correct when it stays for a while and then pulls the data again?

I am following the js_sub.c in the provided example where the differences are {
example : s = js_SubscribeSync(&sub, js, subj, &jsOpts, &so, &jerr);
my : s = js_SubscribeSync(&sub, js, subj, &jsOpts, NULL, NULL); }
}
where example's so is initialized as follows{
jsSubOptions so;
if (s == NATS_OK)
{
so.Stream = stream;
so.Consumer = durable;
if (flowctrl)
{
so.Config.FlowControl = true;
so.Config.Heartbeat = (int64_t)1E9;
}
}
}
my :{
jsSubOptions so;
if (s == NATS_OK)
{
so.Stream = stream;
so.Consumer = durable;
}
}
When I also use , it reports at runtime:NOT FOUND

Expected behavior

The fetched sequence is the same as the published sequence, and there is no duplication of receiving the received data

Server and client version

nats-server is 2.9.21
natsclient-c 3.61

Host environment

windows10 cpu :i9-12900

Steps to reproduce

No response

@li1786422 li1786422 added the defect Suspected defect such as a bug or regression label Oct 26, 2023
@li1786422 li1786422 changed the title 请使用 js_SubscribeSync(&sub, js, subj, &jsOpts, NULL, NULL); 订阅主题,然后通过 while(1){ natsSubscription_NextMsg(&msg, sub, 5000);订阅主题 if (s != NATS_OK) 中断; if (start == 0) start = nats_Now(); s = natsMsg_NextMsg(sub, 5000); if (s ! = NATS_OK) sleep(1)//sleep 1 seconds this is pseudocode s = natsMsg_Ack(msg, nullptr); The method natsMsg_Destroy(msg); 不断 打印数据,取到的数据顺序乱码是什么原因 客户端拉数据时,停留一段时间再拉数据时如何保证数据顺序正确? Subscription Data Disorder Problem Oct 26, 2023
@li1786422
Copy link
Author

When I remove sleep, after getting data up to 1000 data it pauses for a while before going to start the subscription from the beginning, where the 1000 data are in order

@levb levb self-assigned this Oct 26, 2023
@levb
Copy link
Collaborator

levb commented Oct 26, 2023

@li1786422 Apologies if I am misunderstanding your issue, but it seems to me that you want your stream configured with a js_InterestPolicy if you want the messages to be removed by explicit ACKs, or with a js_WorkQueuePolicy if you want them to be pulled once. See https://docs.nats.io/nats-concepts/jetstream/streams#retentionpolicy

Please let me know if I misunderstood the issue.

@li1786422
Copy link
Author

li1786422 commented Oct 27, 2023

@li1786422 Apologies if I am misunderstanding your issue, but it seems to me that you want your stream configured with a js_InterestPolicy if you want the messages to be removed by explicit ACKs, or with a js_WorkQueuePolicy if you want them to be pulled once. See https://docs.nats.io/nats-concepts/jetstream/streams#retentionpolicy

Please let me know if I misunderstood the issue.
this my code
publish code :
publishcode.txt

subscribe code :
subscribecode.txt

Scenario 1
Parameters to enter when running the subscription program
Enter the topic you want to subscribe to: foo1
Enter the subscription method:3

running result:
publishMessage.txt
subscribemessage.txt

from subscribe.txt . I found that the data I obtained after hellofoo1_1459 becomes hellofoo1_460 and the data after that is disordered
Is this due to not creating a consumer?
but When I try to put on a piece of consumption this is reported as
Error: 13 - Not Found Error: 13 - Not Found
The code I'm trying to create the CONSUMER with is changing to b
js_SubscribeSync(&sub, js, subject.c_str(), &jsOpts, nullptr, nullptr); to
js_SubscribeSync(&sub, js, subject.c_str(), &jsOpts, &so, nullptr);

Scenario 2
Parameters to enter when running the subscription program
Enter the topic you want to subscribe to: foo1
Enter the subscription method:1
running result:
I can't get the data.

I did debugging and found that js_PullSubscribe is successful but natsSubscription_Fetch doesn't fetch the data, I don't understand why that is

my nats-server configuration file :
config.txt

@levb
Copy link
Collaborator

levb commented Oct 27, 2023

@li1786422 Thank you for providing the code snippets, they should help to understand/fix the issue. Unfortunately they seem to be encoded and I can't see them when downloaded. Do you mind pasting in the ticket or using https://gist.github.com/?

@li1786422
Copy link
Author

li1786422 commented Oct 27, 2023

@li1786422 Thank you for providing the code snippets, they should help to understand/fix the issue. Unfortunately they seem to be encoded and I can't see them when downloaded. Do you mind pasting in the ticket or using https://gist.github.com/?
you can also see :
https://gist.github.com/li1786422/ef00570081dca4d414ae9095bacfba65

this is not encode ,you can try :
this my code
publish code :
publishcode.txt

subscribe code :
subscribecode.txt

Scenario 1
Parameters to enter when running the subscription program
Enter the topic you want to subscribe to: foo1
Enter the subscription method:3

running result:
publishMessage.txt
subscribemessage.txt

from subscribe.txt . I found that the data I obtained after hellofoo1_1459 becomes hellofoo1_460 and the data after that is disordered
Is this due to not creating a consumer?
but When I try to put on a piece of consumption this is reported as
Error: 13 - Not Found Error: 13 - Not Found
The code I'm trying to create the CONSUMER with is changing to b
js_SubscribeSync(&sub, js, subject.c_str(), &jsOpts, nullptr, nullptr); to
js_SubscribeSync(&sub, js, subject.c_str(), &jsOpts, &so, nullptr);

Scenario 2
Parameters to enter when running the subscription program
Enter the topic you want to subscribe to: foo1
Enter the subscription method:1
running result:
I can't get the data.

I did debugging and found that js_PullSubscribe is successful but natsSubscription_Fetch doesn't fetch the data, I don't understand why that is

my nats-server configuration file :
config.txt

@levb
Copy link
Collaborator

levb commented Oct 27, 2023

@li1786422
Copy link
Author

@li1786422 maybe unrelated, but in https://gist.github.com/li1786422/ef00570081dca4d414ae9095bacfba65#file-subscribecode-txt-L96, was it supposed to be 3?

Hi I've re-uploaded the file and now the comments section can be downloaded normally without the encoding

@li1786422
Copy link
Author

@li1786422 maybe unrelated, but in https://gist.github.com/li1786422/ef00570081dca4d414ae9095bacfba65#file-subscribecode-txt-L96, was it supposed to be 3?

Can you tell me if the downloaded code is still messed up?

@levb
Copy link
Collaborator

levb commented Oct 28, 2023 via email

@li1786422
Copy link
Author

I got the samples and the data, sorry was distracted with another big and didn't get a chance to review it in detail.

On Fri, Oct 27, 2023, 5:45 PM li1786422 @.> wrote: @li1786422 https://github.com/li1786422 maybe unrelated, but in https://gist.github.com/li1786422/ef00570081dca4d414ae9095bacfba65#file-subscribecode-txt-L96, was it supposed to be 3? Can you tell me if the downloaded code is still messed up? — Reply to this email directly, view it on GitHub <#690 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJB46HEKG3BXPDIFMONNH3YBRITXAVCNFSM6AAAAAA6QIDGO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBTGY2DCNJYGQ . You are receiving this because you were assigned.Message ID: <nats-io/nats .@.>

That's fine, I just wanted to make sure you could get the data correctly, just look at it when you have the time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Suspected defect such as a bug or regression
Projects
None yet
Development

No branches or pull requests

2 participants