I have a project that I've upgraded to a recent version of spring boot and spring cloud and noticed some unexpected behaviour.
spring-boot: 2.5.2
spring-cloud 2020.0.3
Also worth noting, I have downgraded spring-kaka due to issue https://github.com/spring-cloud/spring-cloud-stream-binder-kafka/issues/1079
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.6.7</version>
</dependency>
I have logging turned on for:
<logger name="org.apache.kafka.clients.consumer.ConsumerConfig" level="info"/>
My spring yaml is as follows:
spring:
kafka:
bootstrap-servers: localhost:9092
consumer:
auto-offset-reset: latest
**enable-auto-commit: true**
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: myapp.serde.MyCustomDeserializer
producer:
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: myapp.serde.MyCustomSerializer
properties:
security:
protocol: PLAINTEXT
cloud:
stream:
default:
producer:
useNativeEncoding: true
consumer:
useNativeEncoding: true
bindings:
myInboundRoute:
destination: some-destination.1
group: a-custom-group
myOutboundRoute:
destination: some-destination.2
I see the following output when I start the application:
[2021-07-09 21:41:42,310] [main] INFO org.apache.kafka.clients.consumer.ConsumerConfig: ConsumerConfig values:
allow.auto.create.topics = true
auto.commit.interval.ms = 100
auto.offset.reset = latest
bootstrap.servers = [localhost:9092]
check.crcs = true
client.dns.lookup = use_all_dns_ips
client.id = consumer-a-custom-group-1
client.rack =
connections.max.idle.ms = 540000
default.api.timeout.ms = 60000
enable.auto.commit = false
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = a-custom-group
group.instance.id = null
heartbeat.interval.ms = 3000
interceptor.classes = []
internal.leave.group.on.close = true
internal.throw.on.fetch.stable.offset.unsupported = false
isolation.level = read_uncommitted
key.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 500
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor]
receive.buffer.bytes = 65536
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
security.providers = null
send.buffer.bytes = 131072
session.timeout.ms = 10000
socket.connection.setup.timeout.max.ms = 127000
socket.connection.setup.timeout.ms = 10000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.3]
ssl.endpoint.identification.algorithm = https
ssl.engine.factory.class = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.certificate.chain = null
ssl.keystore.key = null
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLSv1.3
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.certificates = null
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
value.deserializer = class myapp.serde.MyCustomDeserializer
[2021-07-09 21:41:42,371] [main] INFO org.apache.kafka.clients.consumer.ConsumerConfig: ConsumerConfig values:
allow.auto.create.topics = true
auto.commit.interval.ms = 100
auto.offset.reset = latest
bootstrap.servers = [localhost:9092]
check.crcs = true
client.dns.lookup = use_all_dns_ips
client.id = consumer-a-custom-group-2
client.rack =
connections.max.idle.ms = 540000
default.api.timeout.ms = 60000
enable.auto.commit = false
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = a-custom-group
group.instance.id = null
heartbeat.interval.ms = 3000
interceptor.classes = []
internal.leave.group.on.close = true
internal.throw.on.fetch.stable.offset.unsupported = false
isolation.level = read_uncommitted
key.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 500
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor]
receive.buffer.bytes = 65536
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
security.providers = null
send.buffer.bytes = 131072
session.timeout.ms = 10000
socket.connection.setup.timeout.max.ms = 127000
socket.connection.setup.timeout.ms = 10000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.3]
ssl.endpoint.identification.algorithm = https
ssl.engine.factory.class = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.certificate.chain = null
ssl.keystore.key = null
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLSv1.3
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.certificates = null
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
value.deserializer = class myapp.serde.MyCustomDeserializer
[2021-07-09 21:41:42,542] [main] INFO com.me.MyApplication: Started MyApplication in 3.164 seconds (JVM running for 3.875)
[2021-07-09 21:41:42,579] [kafka-binder-health-1] INFO org.apache.kafka.clients.consumer.ConsumerConfig: ConsumerConfig values:
allow.auto.create.topics = true
auto.commit.interval.ms = 5000
auto.offset.reset = latest
bootstrap.servers = [localhost:9092]
check.crcs = true
client.dns.lookup = use_all_dns_ips
client.id = consumer-null-3
client.rack =
connections.max.idle.ms = 540000
default.api.timeout.ms = 60000
enable.auto.commit = true
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = null
group.instance.id = null
heartbeat.interval.ms = 3000
interceptor.classes = []
internal.leave.group.on.close = true
internal.throw.on.fetch.stable.offset.unsupported = false
isolation.level = read_uncommitted
key.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 500
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor]
receive.buffer.bytes = 65536
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
security.providers = null
send.buffer.bytes = 131072
session.timeout.ms = 10000
socket.connection.setup.timeout.max.ms = 127000
socket.connection.setup.timeout.ms = 10000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.3]
ssl.endpoint.identification.algorithm = https
ssl.engine.factory.class = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.certificate.chain = null
ssl.keystore.key = null
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLSv1.3
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.certificates = null
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
value.deserializer = class myapp.serde.MyCustomDeserializer
[2021-07-09 21:41:52,391] [pool-2-thread-1] INFO org.apache.kafka.clients.consumer.ConsumerConfig: ConsumerConfig values:
allow.auto.create.topics = true
auto.commit.interval.ms = 5000
auto.offset.reset = latest
bootstrap.servers = [localhost:9092]
check.crcs = true
client.dns.lookup = use_all_dns_ips
client.id = consumer-a-custom-group-4
client.rack =
connections.max.idle.ms = 540000
default.api.timeout.ms = 60000
enable.auto.commit = true
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = a-custom-group
group.instance.id = null
heartbeat.interval.ms = 3000
interceptor.classes = []
internal.leave.group.on.close = true
internal.throw.on.fetch.stable.offset.unsupported = false
isolation.level = read_uncommitted
key.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 500
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor]
receive.buffer.bytes = 65536
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
security.providers = null
send.buffer.bytes = 131072
session.timeout.ms = 10000
socket.connection.setup.timeout.max.ms = 127000
socket.connection.setup.timeout.ms = 10000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.3]
ssl.endpoint.identification.algorithm = https
ssl.engine.factory.class = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.certificate.chain = null
ssl.keystore.key = null
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLSv1.3
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.certificates = null
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
value.deserializer = class myapp.serde.MyCustomDeserializer
If you look at the client.id property logged out, you will see it is index 1, 2, 3 and 4. You'll also notice in the log the thread name being captured e.g. [main].
Question: In my configuration I have enable-auto-commit: true and yet in the log it clearly shows the property enable.auto.commit being false for consumers 1 and 2. consumer 3 (the binder health one) and consumer 4 (in thread pool-2-thread-1) have it set to true.
Before upgrading, I was using boot 2.1.7 and Cloud Greenwich.SR1. The output for that showed the enable.auto.commit always set to true as per my config. Is this a bug in the logging or more serious than that?
enable.auto.commit=true is not recommended - the listener container commits the offsets in a more deterministic manner - either after each record or each batch of records returned by the poll.
It has been set to false (unless explicitly set by a property) since version 2.3 of Spring for Apache Kafka.
https://github.com/spring-projects/spring-kafka/issues/945
Related
I have 3 Nginx servers running on a single host and have a diffuculty to set up correctly in Telegraf. Here is the current setup for one Nginx server and need to add two inputs which are for decoding log files for other two servers. Any help would be appreciated!
#nginx-metrics and logs
[[inputs.nginx]]
urls = ["https://example.com/nginx_status"]
response_timeout = "5s"
[[inputs.tail]]
name_override = "nginxlog"
files = ["/var/www/example/logs/http-access.log"]
from_beginning = false
pipe = false
data_format = "grok"
grok_patterns = ["%{COMBINED_LOG_FORMAT}"]
[[inputs.exec]]
commands = [
"sh /etc/telegraf/nginx_stats.sh"
]
timeout = "5s"
name_override = "nginx_response_code"
data_format = "json"
tag_keys = [
"resp_code"
]
[[outputs.prometheus_client]]
listen = "0.0.0.0:9125"
For example, something like this.
[[inputs.tail]]
name_override = "nginxlog"
files = ["/var/www/example2/logs/http-access.log"]
from_beginning = false
pipe = false
data_format = "grok"
grok_patterns = ["%{COMBINED_LOG_FORMAT}"]
[[inputs.exec]]
commands = [
"sh /etc/telegraf/nginx_stats2.sh"
]
timeout = "5s"
name_override = "nginx_response_code"
data_format = "json"
tag_keys = [
"resp_code"
]
[[inputs.tail]]
name_override = "nginxlog"
files = ["/var/www/example3/logs/http-access.log"]
from_beginning = false
pipe = false
data_format = "grok"
grok_patterns = ["%{COMBINED_LOG_FORMAT}"]
[[inputs.exec]]
commands = [
"sh /etc/telegraf/nginx_stats3.sh"
]
timeout = "5s"
name_override = "nginx_response_code"
data_format = "json"
tag_keys = [
"resp_code"
]
I'm using a simple listener factory with SeekToCurrentErrorhandler with FixedBackOff:
#Bean
public ConcurrentKafkaListenerContainerFactory<String, String> stringKafkaListenerContainerFactory(KafkaProperties kafkaProperties) {
ErrorHandlingDeserializer<String> errorHandlingDeserializer = new ErrorHandlingDeserializer<>(new StringDeserializer());
ConsumerFactory<String, String> consumerFactory = new DefaultKafkaConsumerFactory<>(kafkaProperties.buildConsumerProperties(),
errorHandlingDeserializer, errorHandlingDeserializer);
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory);
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.RECORD);
factory.setErrorHandler(new SeekToCurrentErrorHandler(new FixedBackOff(10000L, 10L)));
factory.setStatefulRetry(true);
return factory;
}
This configuration is working only partly: it stops (with finally logging ERROR org.springframework.kafka.listener.SeekToCurrentErrorHandler - Backoff FixedBackOff{interval=10000000, currentAttempts=11, maxAttempts=10} exhausted for ...) after the 10 retries - but the interval of 10000ms is ignored: it retries without any delay.
I don't understand why the interval gets ignored...
ConsumerConfig logs following on startup:
2021-05-10 12:19:30,491 [main] INFO org.apache.kafka.clients.consumer.ConsumerConfig - ConsumerConfig values:
allow.auto.create.topics = true
auto.commit.interval.ms = 5000
auto.offset.reset = earliest
bootstrap.servers = [broker:29092]
check.crcs = true
client.dns.lookup = use_all_dns_ips
client.id = some-service-0
client.rack =
connections.max.idle.ms = 540000
default.api.timeout.ms = 60000
enable.auto.commit = false
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = commissioning
group.instance.id = null
heartbeat.interval.ms = 3000
interceptor.classes = []
internal.leave.group.on.close = true
internal.throw.on.fetch.stable.offset.unsupported = false
isolation.level = read_committed
key.deserializer = class org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 500
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor]
receive.buffer.bytes = 65536
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
security.providers = null
send.buffer.bytes = 131072
session.timeout.ms = 10000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2]
ssl.endpoint.identification.algorithm = https
ssl.engine.factory.class = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLSv1.2
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
value.deserializer = class org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
any idea why this interval gets ignored?
Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Calendar1.SelectionChanged
Dim db As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\jonhny\Desktop\FinalProject\Backup\Backup\Backup\FinalProject\Database.accdb'")
If db.State = ConnectionState.Open Then
db.Close()
End If
db.Open()
Dim reservationDate As String = Calendar1.SelectedDate
Dim reserved As String
Dim table As String
Dim booking As String = "SELECT BookingDate, NumberOfTable FROM CustomerReservation WHERE BookingDate='" & reservationDate & "'"
Dim sqlcommand1 As New OleDbCommand(booking, db)
Dim dr1 As OleDbDataReader
dr1 = sqlcommand1.ExecuteReader
If dr1.HasRows Then
dr1.Read()
reserved = dr1.Item("BookingDate")
Table = dr1.Item("NumberOfTable")
End If
dr1.Close()
If reservationDate < DateTime.Now.AddDays(-1) Then
lblShowMessage.Text = "*You can't select previous date!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
ElseIf reservationDate < DateTime.Now.AddDays(7) Then
lblShowMessage.Text = "*You have to reserve 7 days earlier!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
ElseIf reservationDate = reserved Then
lblShowMessage.Text = "*This day not Available!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
Button1.Visible = True
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
Button5.Visible = True
Button6.Visible = True
Button7.Visible = True
Button8.Visible = True
Button9.Visible = True
Button11.Visible = True
Button12.Visible = True
Button13.Visible = True
Button14.Visible = True
Button15.Visible = True
Button16.Visible = True
Button17.Visible = True
Button18.Visible = True
If Button1.Text = table Then
Button1.Visible = False
End If
If Button2.Text = table Then
Button2.Visible = False
End If
If Button3.Text = table Then
Button3.Visible = False
End If
If Button7.Text = table Then
Button7.Visible = False
End If
If Button11.Text = table Then
Button11.Visible = False
End If
Else
lblShowMessage.Text = "Available to Reserve"
lblShowMessage.ForeColor = Drawing.Color.Green
lblShowDate.Text = Calendar1.SelectedDate
BookingdateTextBox.Text = Calendar1.SelectedDate
btnPToPayment.Visible = True
Button1.Visible = True
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
Button5.Visible = True
Button6.Visible = True
Button7.Visible = True
Button8.Visible = True
Button9.Visible = True
Button11.Visible = True
Button12.Visible = True
End If
db.Close()
End Sub
it only can disable 1 button, how can to disable more then 2 button at same time?
I would suggest you change the logic to include a while loop:
dr1 = sqlcommand1.ExecuteReader
Dim count As Integer = dr1.FieldCount
While reader.Read()
For i As Integer = 0 To count - 1
reserved = dr1.Item("BookingDate")
Table = dr1.Item("NumberOfTable")
If reservationDate < DateTime.Now.AddDays(-1) Then
lblShowMessage.Text = "*You can't select previous date!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
ElseIf reservationDate < DateTime.Now.AddDays(7) Then
lblShowMessage.Text = "*You have to reserve 7 days earlier!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
ElseIf reservationDate = reserved Then
lblShowMessage.Text = "*This day not Available!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
Button1.Visible = True
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
Button5.Visible = True
Button6.Visible = True
Button7.Visible = True
Button8.Visible = True
Button9.Visible = True
Button11.Visible = True
Button12.Visible = True
Button13.Visible = True
Button14.Visible = True
Button15.Visible = True
Button16.Visible = True
Button17.Visible = True
Button18.Visible = True
If Button1.Text = table Then
Button1.Visible = False
End If
If Button2.Text = table Then
Button2.Visible = False
End If
If Button3.Text = table Then
Button3.Visible = False
End If
If Button7.Text = table Then
Button7.Visible = False
End If
If Button11.Text = table Then
Button11.Visible = False
End If
Else
lblShowMessage.Text = "Available to Reserve"
lblShowMessage.ForeColor = Drawing.Color.Green
lblShowDate.Text = Calendar1.SelectedDate
BookingdateTextBox.Text = Calendar1.SelectedDate
btnPToPayment.Visible = True
Button1.Visible = True
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
Button5.Visible = True
Button6.Visible = True
Button7.Visible = True
Button8.Visible = True
Button9.Visible = True
Button11.Visible = True
Button12.Visible = True
End If
Next
End While
dr1.Close()
So what this will do is for every row in the data reader it will run the check to set the reserved and table information, then allow you to run the logic against every row rather than against 1 row which is essentially what you are doing currently.
Additional suggestions
Give your buttons meaningful names like : ReserveTableOne, ReserveTableTwo rather than just button1 and button2 - helps when you revisit the code later on.
Change If reservationDate < DateTime.Now.AddDays(-1) to If reservationDate <= DateTime.Now.AddDays(-1) otherwise it'll only do it if it's less than yesterday rather than less than or equal to yesterday - which is what you need.
Change ElseIf reservationDate < DateTime.Now.AddDays(7) to ElseIf reservationDate > DateTime.Now.AddDays(7) which I think should be correct if you only allow people to reserve up to one week ahead, otherwise that won't allow you to reserve tables that are more than 7 days from now.
I have an issue with a dynamically created table within my asp form.
To control the page and create the table, the user selects a date range and clicks a Refresh button.
The table creates after being populated in the code behind, but duplicates,
i.e. 11 rows should populate, but after row 11, rows 12 - 22 are duplicates of 1 - 11.
Interestingly, when clicking a button (created by the code behind, dynamically) the page posts back with the table being as it should rows 1 - 11 and no more. I have replicated the code below in my Page_Load sub.
Please advise, thanks in advance;
Protected Sub Refresh_Click(sender As Object, e As EventArgs)
'/*** CREATES CONNECTION STRING AND OPENS CONNECTION TO DB ***\'
Dim cn As New OleDbConnection
cn.ConnectionString = [String]
cn.Open()
'/*** CREATES DateFormat FOR PLACEMENT WITHIN THE SQL ***\'
Dim dtform As String
dtform = "dd-MMM-yyyy"
'/*** DECLARES AND FINDS FROM & TO DATE FOR SQL STATEMENT ***\'
Dim from As Date
from = Frmdt.Text
Dim todat As Date
todat = Todt.Text
'/*** EXECUTES SQL & CREATES RECORDSET WITH RecordCount ***\'
Dim rs As New ADODB.Recordset()
Dim x As Integer
With rs
.CursorLocation = ADODB.CursorLocationEnum.adUseClient
.CursorType = ADODB.CursorTypeEnum.adOpenStatic
.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic
.Open("SELECT * FROM DB", cn.ConnectionString)
x = rs.RecordCount
End With
'/*** DECLARES & FILLS DataAdapter, DataSet & DataTable ***\'
Dim da As New OleDbDataAdapter()
Dim ds As New DataSet()
da.Fill(ds, rs, "[Field Headers]")
Dim dt As DataTable = ds.Tables("[Field Headers]")
'/*** DECLARES ROW COUNTER TO TRACK NUMBER OF ROWS ADDED TO ASP:TABLE ***\'
Dim rwcntr As Integer
'/*** DECLARES ROW COUNTER TO EXTRACT DATA FROM DataTable ***\'
Dim i As Integer
rwcntr = 1
'/*** BEGINS LOOP OF DataTable & CREATES ASP:TABLE, ENDING WHEN ROW COUNTER REACHES RecordCount MINUS 1 ***\'
For i = 0 To x - 1 Step +1
Dim td As New TableCell()
Dim td2 As New TableCell()
Dim td3 As New TableCell()
Dim td4 As New TableCell()
Dim td5 As New TableCell()
Dim td6 As New TableCell()
Dim td7 As New TableCell()
Dim td8 As New TableCell()
Dim td9 As New TableCell()
Dim td10 As New TableCell()
Dim td11 As New TableCell()
Dim td12 As New TableCell()
Dim td13 As New TableCell()
Dim tr As New TableRow()
td.Text = dt.Rows(i)("[Field Header1]").ToString()
td.Font.Name = "Calibri"
td.BackColor = ColorTranslator.FromHtml("#cccccc")
td.ForeColor = Color.Black
td.Font.Size = 8
td.BorderStyle = WebControls.BorderStyle.Inset
td.BorderColor = Color.Black
td.BorderWidth = 1.5
td.EnableViewState = True
td.HorizontalAlign = WebControls.HorizontalAlign.Center
td.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td)
td2.Text = dt.Rows(i)("[Field Header2]").ToString()
td2.Font.Name = "Calibri"
td2.BackColor = ColorTranslator.FromHtml("#cccccc")
td2.ForeColor = Color.Black
td.BorderWidth = 1.5
td2.Font.Size = 8
td2.BorderStyle = WebControls.BorderStyle.Inset
td2.BorderColor = Color.Black
td2.BorderWidth = 1.5
td2.EnableViewState = True
td2.HorizontalAlign = WebControls.HorizontalAlign.Center
td2.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td2)
td3.Text = dt.Rows(i)("[Field Header3]").ToString()
td3.Font.Name = "Calibri"
td3.BackColor = ColorTranslator.FromHtml("#cccccc")
td3.ForeColor = Color.Black
td3.BorderWidth = 1.5
td3.Font.Size = 8
td3.BorderStyle = WebControls.BorderStyle.Inset
td3.BorderColor = Color.Black
td.BorderWidth = 1.5
td3.EnableViewState = True
td3.HorizontalAlign = WebControls.HorizontalAlign.Center
td3.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td3)
td4.Text = dt.Rows(i)("[Field Header4]").ToString()
td4.Font.Name = "Calibri"
td4.BackColor = ColorTranslator.FromHtml("#cccccc")
td4.ForeColor = Color.Black
td4.Font.Size = 8
td4.BorderStyle = WebControls.BorderStyle.Inset
td4.BorderColor = Color.Black
td4.BorderWidth = 1.5
td4.EnableViewState = True
td4.HorizontalAlign = WebControls.HorizontalAlign.Center
td4.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td4)
td5.Text = dt.Rows(i)("[Field Header5]").ToString()
td5.Font.Name = "Calibri"
td5.BackColor = ColorTranslator.FromHtml("#cccccc")
td5.ForeColor = Color.Black
td5.Font.Size = 8
td5.BorderStyle = WebControls.BorderStyle.Inset
td5.BorderColor = Color.Black
td5.BorderWidth = 1.5
td5.EnableViewState = True
td5.HorizontalAlign = WebControls.HorizontalAlign.Center
td5.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td5)
td6.Text = dt.Rows(i)("[Field Header6]").ToString()
td6.Font.Name = "Calibri"
td6.BackColor = ColorTranslator.FromHtml("#cccccc")
td6.ForeColor = Color.Black
td6.Font.Size = 8
td6.BorderStyle = WebControls.BorderStyle.Inset
td6.BorderColor = Color.Black
td6.BorderWidth = 1.5
td6.EnableViewState = True
td6.HorizontalAlign = WebControls.HorizontalAlign.Center
td6.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td6)
td7.Text = dt.Rows(i)("[Field Header7]").ToString()
td7.Font.Name = "Calibri"
td7.BackColor = ColorTranslator.FromHtml("#cccccc")
td7.ForeColor = Color.Black
td7.Font.Size = 8
td7.BorderStyle = WebControls.BorderStyle.Inset
td7.BorderColor = Color.Black
td7.BorderWidth = 1.5
td7.EnableViewState = True
td7.HorizontalAlign = WebControls.HorizontalAlign.Center
td7.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td7)
td8.Text = dt.Rows(i)("[Field Header8]").ToString()
td8.Font.Name = "Calibri"
td8.BackColor = ColorTranslator.FromHtml("#cccccc")
td8.ForeColor = Color.Black
td8.Font.Size = 8
td8.BorderStyle = WebControls.BorderStyle.Inset
td8.BorderColor = Color.Black
td8.BorderWidth = 1.5
td8.EnableViewState = True
td8.HorizontalAlign = WebControls.HorizontalAlign.Center
td8.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td8)
td9.Text = dt.Rows(i)("[Field Header9]").ToString()
td9.Font.Name = "Calibri"
td9.BackColor = ColorTranslator.FromHtml("#cccccc")
td9.ForeColor = Color.Black
td9.Font.Size = 8
td9.BorderStyle = WebControls.BorderStyle.Inset
td9.BorderColor = Color.Black
td9.BorderWidth = 1.5
td9.Width = 25
td9.EnableViewState = True
td9.HorizontalAlign = WebControls.HorizontalAlign.Center
td9.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td9)
'td10.Text = dt.Rows(i)("[Field Header10]").ToString()
'td10.Font.Name = "Calibri"
td10.BackColor = ColorTranslator.FromHtml("#cccccc")
td10.ForeColor = Color.Black
'td10.Font.Size = 8
td10.BorderStyle = WebControls.BorderStyle.Inset
td10.BorderColor = Color.Black
td10.BorderWidth = 1.5
td10.EnableViewState = True
'/*** SHOULD DATA BE AVAILABLE CREATES ASP:BUTTON TO COPY TO CLIPBOARD LATER ***\'
If Len(dt.Rows(i)("[Field Header10]").ToString()) > 0 Then
Dim btn As New Button
td10.Controls.Add(btn)
btn.Text = dt.Rows(i)("[Field Header10]").ToString()
btn.Font.Name = "Calibri"
btn.Font.Size = 8
td10.HorizontalAlign = WebControls.HorizontalAlign.Center
td10.VerticalAlign = VerticalAlign.Middle
btn.EnableViewState = True
AddHandler btn.Click, AddressOf OnDbleClick
End If
tr.Controls.Add(td10)
td11.Text = dt.Rows(i)("[Field Header11]").ToString()
td11.Font.Name = "Calibri"
td11.BackColor = ColorTranslator.FromHtml("#cccccc")
td11.ForeColor = Color.Black
td11.Font.Size = 8
td11.BorderStyle = WebControls.BorderStyle.Inset
td11.BorderColor = Color.Black
td11.BorderWidth = 1.5
td11.EnableViewState = True
td11.HorizontalAlign = WebControls.HorizontalAlign.Center
td11.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td11)
td12.Text = dt.Rows(i)("[Field Header12]").ToString()
td12.Font.Name = "Calibri"
td12.BackColor = ColorTranslator.FromHtml("#cccccc")
td12.ForeColor = Color.Black
td12.Font.Size = 8
td12.BorderStyle = WebControls.BorderStyle.Inset
td12.BorderColor = Color.Black
td12.BorderWidth = 1.5
td12.EnableViewState = True
td12.HorizontalAlign = WebControls.HorizontalAlign.Center
td12.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td12)
td13.Text = dt.Rows(i)("[Field Header13]").ToString()
td13.Font.Name = "Calibri"
td13.BackColor = ColorTranslator.FromHtml("#cccccc")
td13.ForeColor = Color.Black
td13.Font.Size = 8
td13.BorderStyle = WebControls.BorderStyle.Inset
td13.BorderColor = Color.Black
td13.BorderWidth = 1.5
td13.EnableViewState = True
td13.HorizontalAlign = WebControls.HorizontalAlign.Center
td13.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td13)
'/*** ADDS ROW ONCE CELLS ARE COMPLETE ***\'
itemstable.Controls.AddAt(rwcntr, tr)
rwcntr = rwcntr + 1
Next
end sub
I'm trying to get postfix to deliver mail to gmail. I've followed this article on configuring it, but I still gives me an error:
relay=smtp.gmail.com[173.194.66.108]:587, delay=0.46, delays=0.05/0/0.37/0.04,
dsn=5.5.1, status=bounced (host smtp.gmail.com[173.194.66.108] said: 530-5.5.1
Authentication Required.
http://mhawthorne.net/posts/postfix-configuring-gmail-as-relay.html
What am I missing?
Here's my postfix config:
alias_maps = hash:/etc/aliases
biff = no
canonical_maps = hash:/etc/postfix/canonical
command_directory = /usr/sbin
config_directory = /etc/postfix
content_filter =
daemon_directory = /usr/lib/postfix
data_directory = /var/lib/postfix
debug_peer_level = 3
debug_peer_list = smtp.gmail.com
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin $daemon_directory/$process_name $process_id & sleep 5
defer_transports =
delay_warning_time = 1h
disable_dns_lookups = no
disable_mime_output_conversion = no
html_directory = /usr/share/doc/packages/postfix-doc/html
inet_interfaces = localhost
inet_protocols = all
mail_owner = postfix
mail_spool_directory = /var/mail
mailbox_command =
mailbox_size_limit = 0
mailbox_transport =
mailq_path = /usr/bin/mailq
manpage_directory = /usr/share/man
masquerade_classes = envelope_sender, header_sender, header_recipient
masquerade_domains =
masquerade_exceptions = root
message_size_limit = 0
message_strip_characters = \0
mydestination = $myhostname, localhost.$mydomain
myhostname = suse.home
mynetworks_style = subnet
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/packages/postfix-doc/README_FILES
relay_clientcerts =
relayhost = [smtp.gmail.com]:587
relocated_maps = hash:/etc/postfix/relocated
sample_directory = /usr/share/doc/packages/postfix-doc/samples
sender_canonical_maps = hash:/etc/postfix/sender_canonical
sendmail_path = /usr/sbin/sendmail
setgid_group = maildrop
smtp_enforce_tls = no
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile =
smtp_tls_CApath = /etc/postfix/ssl/cacerts
smtp_tls_cert_file =
smtp_tls_key_file =
smtp_tls_session_cache_database = btree:/var/lib/postfix/smtpd_tls_session_cache
smtp_use_tls = yes
smtpd_client_restrictions =
smtpd_helo_required = no
smtpd_helo_restrictions =
smtpd_recipient_restrictions = permit_mynetworks,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sender_restrictions = hash:/etc/postfix/access
smtpd_tls_CAfile =
smtpd_tls_CApath =
smtpd_tls_ask_ccert = no
smtpd_tls_cert_file =
smtpd_tls_key_file =
smtpd_tls_received_header = no
smtpd_use_tls = no
strict_8bitmime = no
strict_rfc821_envelopes = no
transport_maps = hash:/etc/postfix/transport
unknown_local_recipient_reject_code = 550
virtual_alias_domains = hash:/etc/postfix/virtual
virtual_alias_maps = hash:/etc/postfix/virtual
You most likely need to go to Google's unlock page, as the new IP address trying to send the mail is raising security concerns.
Once you have unlocked via the browser, the script will be able to send.