This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.4.22 <0.9.0; | |
contract SampleContract { | |
uint storedData; | |
function set(uint x) public { | |
storedData = x; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max_over_time(sync_last_processed_doc_at[24h]) - max_over_time(sync_last_seen_doc_at[24h]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max_over_time(sync_last_seen_oplog_at[24h]) - ignoring(instance, job) max_over_time(sync_last_seen_doc_at[24h]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gauge.builder("sync.last.seen.doc.at", this, listener -> listener.lastSeenAt.get()) | |
.strongReference(true) | |
.register(Metrics.globalRegistry); | |
Gauge.builder("sync.last.processed.doc.at", this, listener -> listener.lastProcessedAt.get()) | |
.strongReference(true) | |
.register(Metrics.globalRegistry); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gauge.builder("sync.last.seen.oplog.at", this, mongoStats -> mongoStats.lastOplogAt.get()) | |
.strongReference(true) | |
.register(Metrics.globalRegistry); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Query tailQ = new Query().addCriteria(Criteria.where("ns").is("streams.user")); | |
reactiveMongoTemplate.tail(tailQ, OplogEntry.class, "oplog.rs") | |
.retryWhen(Retry.indefinitely().doAfterRetryAsync(signal -> Mono.delay(Duration.ofSeconds(10)).then())) | |
.subscribe(entry -> { | |
log.info("tailed entry: {}", entry); | |
lastOplogAt.set(entry.ts().getTime() * 1000L); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
@Slf4j | |
@Transactional(propagation = Propagation.REQUIRED) | |
@AllArgsConstructor | |
public class SyncToPostgresService { | |
UserEntityRepository userEntityRepository; | |
ResumeTokenRepository resumeTokenRepository; | |
public void syncInASingleTx(User document, String bookmarkToken, Long tokenTimeStamp) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reactiveMongoTemplate | |
.changeStream(User.class) | |
.watchCollection("user") | |
.listen() | |
.subscribe(event -> { | |
log.info("change stream event {}", event); | |
BsonDocument newResumeToken = Objects.requireNonNull(event.getRaw()).getResumeToken().asDocument(); | |
BsonString token = newResumeToken.getString("_data"); | |
var timeStampInMs = Objects.requireNonNull(event.getBsonTimestamp()).getTime() * 1000L; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spring: | |
data: | |
mongodb: | |
host: localhost | |
port: 27017 | |
database: streams |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@AllArgsConstructor | |
public class UserController { | |
UserRepository userRepository; | |
@GetMapping("/user") | |
public Flux<User> getAllUser() { | |
return userRepository.findAll(); |