Ticketing Go लाइब्रेरी
GitHub pkg.go.devरिपॉज़िटरी
उदाहरण
बुनियादी उदाहरण
Application startup पर एक broker बनाकर share करें। wait=0 queue बिना एक immediate attempt है, अधिकतम 255 सेकंड; lease 1–250 सेकंड। अंतिम minimum-work budget अनिवार्य है और 0 हो सकता है। Sub-second ऊपर round होते हैं; out-of-range या normalized lease से बड़ा budget send से पहले reject होता है, clamp नहीं।
import ticketing "github.com/saro-lab/ticketing/ticketing-go"
broker := ticketing.Connect("127.0.0.1:5225")
broker.WaitReady(ctx, 5*time.Second)
ticket, err := broker.Acquire(ctx, "key", 5*time.Second, 30*time.Second, 2*time.Second)
if err != nil {
return err
}
defer ticket.Close()
token := ticket.Token
// In the same DB transaction: verify/update token high-water and perform the business write.Automatic close/drop bounded best-effort release है। Result चाहिए तो explicit release API उपयोग करें। Token को उसी DB transaction में protected write fence करना अनिवार्य है।
जानने योग्य व्यवहार
- एक request byte भी send हुआ हो सकता है तो final response खोने का परिणाम Indeterminate है। समान owner से
Aauto-resend नहीं; caller critical section में नहीं जाता। - Send से पहले cancel unsent; possible-send के बाद session बंद। साथ में grant token parse हो तो bounded compensating exact-token release।
M, हरE, malformed/oversized/unknown response session-fatal हैं। Unresolved possible-send acquire Indeterminate।Bनिश्चित capacity rejection है और तुरंत लौटता है। Internal retry नहीं; caller application backoff के बाद नए owner से नया acquire कर सकता है।- Explicit/compensating release exact token को call/enqueue से पूर्ण 5 सेकंड तक ही retry करता है।
Rsuccess,Nabsent/not current; final response न हो तो error, assumed success नहीं। - Positive conservative remaining time और पर्याप्त work budget पर ही Ticket मिलता है। 250 सेकंड से अधिक work send से पहले unsupported।
- Token DB fencing अनिवार्य: उसी transaction में
token <= stored_high_waterreject, high-water update और business write, फिर commit/rollback और release।
सुरक्षा विकल्प (टोकन · TLS)
हर विकल्प वैकल्पिक है। Token सर्वर के client_tokens से मेल खाना चाहिए, और TLS के चार मोड हैं: बंद / सिस्टम ट्रस्ट स्टोर / एक निर्दिष्ट CA / सत्यापन छोड़ें (केवल परीक्षण के लिए)।
broker, err := ticketing.New(ticketing.Options{
Addrs: []string{"10.0.0.1:5225", "10.0.0.2:5225", "10.0.0.3:5225"},
Token: "123",
TLS: ticketing.TLSSystemRoots(), // TLSOff() | TLSCa("ca.crt") | TLSInsecureSkipVerify()
})आप सर्वर-साइड टोकन, TLS, और क्लस्टर कॉन्फ़िगरेशन Ticketing सर्वर परिनियोजन पृष्ठ पर जनरेट कर सकते हैं।